<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="utf-8"><title>Angular - 路由</title><meta name="Description" content="Angular is a platform for building mobile and desktop web applications.
    Join the community of millions of developers who build compelling user interfaces with Angular."><base href="/"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="search" type="application/opensearchdescription+xml" href="assets/opensearch.xml"><link rel="icon" type="image/x-icon" href="assets/images/favicons/favicon.ico"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-194x194.png" sizes="194x194"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-96x96.png" sizes="96x96"><link rel="icon" type="image/png" href="assets/images/favicons/favicon-16x16.png" sizes="16x16"><link rel="apple-touch-icon" sizes="144x144" href="assets/images/favicons/favicon-144x144.png"><link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/images/favicons/favicon-144x144.png"><link href="assets/fonts/Material_Icons.css" rel="stylesheet"><link href="assets/fonts/Droid_Sans_Mono.css" rel="stylesheet"><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"><link rel="manifest" href="pwa-manifest.json"><meta name="theme-color" content="#1976d2"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="translucent"><script async="" src="assets/js/analytics.js"></script><script>!function(e,a,n,t,s,c,g){e.GoogleAnalyticsObject=s,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(n),g=a.getElementsByTagName(n)[0],c.async=1,c.src="assets/js/analytics.js",~e.name.indexOf("NG_DEFER_BOOTSTRAP")||g.parentNode.insertBefore(c,g)}(window,document,"script",0,"ga")</script><script>window.onerror=function(){ga("send","exception",{exDescription:function(e,r,n,a,c){var l;e=e.replace(/^Error: /,""),l=c?c.stack.replace(/^Error: /,"").replace(e+"\n","").replace(/^ +/gm,"").replace(/^at /gm,"").replace(/(?: \(|@)http.+\/([^/)]+)\)?(?:\n|$)/gm,"@$1\n").replace(/ *\(eval code(:\d+:\d+)\)(?:\n|$)/gm,"@???$1\n"):r+":"+(n=n||"?")+":"+(a=a||"?");return(e+"\n"+l).substr(0,150)}.apply(null,arguments),exFatal:!0})}</script><link rel="stylesheet" href="styles.4adbe52ad34df01b5273.css"><style>.cdk-high-contrast-active .mat-toolbar{outline:solid 1px}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media(max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}</style><style>.mat-icon{background-repeat:no-repeat;display:inline-block;fill:currentColor;height:24px;width:24px}.mat-icon.mat-icon-inline{font-size:inherit;height:inherit;line-height:inherit;width:inherit}[dir=rtl] .mat-icon-rtl-mirror{transform:scale(-1,1)}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon{display:block}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button .mat-icon,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button .mat-icon{margin:auto}</style><style>.mat-button .mat-button-focus-overlay,.mat-icon-button .mat-button-focus-overlay{opacity:0}.mat-button:hover .mat-button-focus-overlay,.mat-stroked-button:hover .mat-button-focus-overlay{opacity:.04}@media(hover:none){.mat-button:hover .mat-button-focus-overlay,.mat-stroked-button:hover .mat-button-focus-overlay{opacity:0}}.mat-button,.mat-flat-button,.mat-icon-button,.mat-stroked-button{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible}.mat-button::-moz-focus-inner,.mat-flat-button::-moz-focus-inner,.mat-icon-button::-moz-focus-inner,.mat-stroked-button::-moz-focus-inner{border:0}.mat-button[disabled],.mat-flat-button[disabled],.mat-icon-button[disabled],.mat-stroked-button[disabled]{cursor:default}.mat-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-button.cdk-program-focused .mat-button-focus-overlay,.mat-flat-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-flat-button.cdk-program-focused .mat-button-focus-overlay,.mat-icon-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-icon-button.cdk-program-focused .mat-button-focus-overlay,.mat-stroked-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-stroked-button.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-button::-moz-focus-inner,.mat-flat-button::-moz-focus-inner,.mat-icon-button::-moz-focus-inner,.mat-stroked-button::-moz-focus-inner{border:0}.mat-raised-button{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1)}.mat-raised-button::-moz-focus-inner{border:0}.mat-raised-button[disabled]{cursor:default}.mat-raised-button.cdk-keyboard-focused .mat-button-focus-overlay,.mat-raised-button.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-raised-button::-moz-focus-inner{border:0}._mat-animation-noopable.mat-raised-button{transition:none;animation:none}.mat-stroked-button{border:1px solid currentColor;padding:0 15px;line-height:34px}.mat-stroked-button .mat-button-focus-overlay,.mat-stroked-button .mat-button-ripple.mat-ripple{top:-1px;left:-1px;right:-1px;bottom:-1px}.mat-fab{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1);min-width:0;border-radius:50%;width:56px;height:56px;padding:0;flex-shrink:0}.mat-fab::-moz-focus-inner{border:0}.mat-fab[disabled]{cursor:default}.mat-fab.cdk-keyboard-focused .mat-button-focus-overlay,.mat-fab.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-fab::-moz-focus-inner{border:0}._mat-animation-noopable.mat-fab{transition:none;animation:none}.mat-fab .mat-button-wrapper{padding:16px 0;display:inline-block;line-height:24px}.mat-mini-fab{box-sizing:border-box;position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:pointer;outline:0;border:none;-webkit-tap-highlight-color:transparent;display:inline-block;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;min-width:64px;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;transform:translate3d(0,0,0);transition:background .4s cubic-bezier(.25,.8,.25,1),box-shadow 280ms cubic-bezier(.4,0,.2,1);min-width:0;border-radius:50%;width:40px;height:40px;padding:0;flex-shrink:0}.mat-mini-fab::-moz-focus-inner{border:0}.mat-mini-fab[disabled]{cursor:default}.mat-mini-fab.cdk-keyboard-focused .mat-button-focus-overlay,.mat-mini-fab.cdk-program-focused .mat-button-focus-overlay{opacity:.12}.mat-mini-fab::-moz-focus-inner{border:0}._mat-animation-noopable.mat-mini-fab{transition:none;animation:none}.mat-mini-fab .mat-button-wrapper{padding:8px 0;display:inline-block;line-height:24px}.mat-icon-button{padding:0;min-width:0;width:40px;height:40px;flex-shrink:0;line-height:40px;border-radius:50%}.mat-icon-button .mat-icon,.mat-icon-button i{line-height:24px}.mat-button-focus-overlay,.mat-button-ripple.mat-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none;border-radius:inherit}.mat-button-ripple.mat-ripple:not(:empty){transform:translateZ(0)}.mat-button-focus-overlay{opacity:0;transition:opacity .2s cubic-bezier(.35,0,.25,1),background-color .2s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable .mat-button-focus-overlay{transition:none}.cdk-high-contrast-active .mat-button-focus-overlay{background-color:#fff}.cdk-high-contrast-black-on-white .mat-button-focus-overlay{background-color:#000}.mat-button-ripple-round{border-radius:50%;z-index:1}.mat-button .mat-button-wrapper>*,.mat-fab .mat-button-wrapper>*,.mat-flat-button .mat-button-wrapper>*,.mat-icon-button .mat-button-wrapper>*,.mat-mini-fab .mat-button-wrapper>*,.mat-raised-button .mat-button-wrapper>*,.mat-stroked-button .mat-button-wrapper>*{vertical-align:middle}.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-prefix .mat-icon-button,.mat-form-field:not(.mat-form-field-appearance-legacy) .mat-form-field-suffix .mat-icon-button{display:block;font-size:inherit;width:2.5em;height:2.5em}.cdk-high-contrast-active .mat-button,.cdk-high-contrast-active .mat-fab,.cdk-high-contrast-active .mat-flat-button,.cdk-high-contrast-active .mat-icon-button,.cdk-high-contrast-active .mat-mini-fab,.cdk-high-contrast-active .mat-raised-button{outline:solid 1px}</style><style>.mat-drawer-container{position:relative;z-index:1;box-sizing:border-box;-webkit-overflow-scrolling:touch;display:block;overflow:hidden}.mat-drawer-container[fullscreen]{top:0;left:0;right:0;bottom:0;position:absolute}.mat-drawer-container[fullscreen].mat-drawer-container-has-open{overflow:hidden}.mat-drawer-container.mat-drawer-container-explicit-backdrop .mat-drawer-side{z-index:3}.mat-drawer-container.ng-animate-disabled .mat-drawer-backdrop,.mat-drawer-container.ng-animate-disabled .mat-drawer-content,.ng-animate-disabled .mat-drawer-container .mat-drawer-backdrop,.ng-animate-disabled .mat-drawer-container .mat-drawer-content{transition:none}.mat-drawer-backdrop{top:0;left:0;right:0;bottom:0;position:absolute;display:block;z-index:3;visibility:hidden}.mat-drawer-backdrop.mat-drawer-shown{visibility:visible}.mat-drawer-transition .mat-drawer-backdrop{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:background-color,visibility}.cdk-high-contrast-active .mat-drawer-backdrop{opacity:.5}.mat-drawer-content{position:relative;z-index:1;display:block;height:100%;overflow:auto}.mat-drawer-transition .mat-drawer-content{transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:transform,margin-left,margin-right}.mat-drawer{position:relative;z-index:4;display:block;position:absolute;top:0;bottom:0;z-index:3;outline:0;box-sizing:border-box;overflow-y:auto;transform:translate3d(-100%,0,0)}.cdk-high-contrast-active .mat-drawer,.cdk-high-contrast-active [dir=rtl] .mat-drawer.mat-drawer-end{border-right:solid 1px currentColor}.cdk-high-contrast-active .mat-drawer.mat-drawer-end,.cdk-high-contrast-active [dir=rtl] .mat-drawer{border-left:solid 1px currentColor;border-right:none}.mat-drawer.mat-drawer-side{z-index:2}.mat-drawer.mat-drawer-end{right:0;transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer{transform:translate3d(100%,0,0)}[dir=rtl] .mat-drawer.mat-drawer-end{left:0;right:auto;transform:translate3d(-100%,0,0)}.mat-drawer-inner-container{width:100%;height:100%;overflow:auto;-webkit-overflow-scrolling:touch}.mat-sidenav-fixed{position:fixed}</style><style>.nav-link.highlight[_ngcontent-ng-docs-c30]{color:#ff0}</style><style>.mat-progress-bar{display:block;height:4px;overflow:hidden;position:relative;transition:opacity 250ms linear;width:100%}._mat-animation-noopable.mat-progress-bar{transition:none;animation:none}.mat-progress-bar .mat-progress-bar-element,.mat-progress-bar .mat-progress-bar-fill::after{height:100%;position:absolute;width:100%}.mat-progress-bar .mat-progress-bar-background{width:calc(100% + 10px)}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-background{display:none}.mat-progress-bar .mat-progress-bar-buffer{transform-origin:top left;transition:transform 250ms ease}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-buffer{border-top:solid 5px;opacity:.5}.mat-progress-bar .mat-progress-bar-secondary{display:none}.mat-progress-bar .mat-progress-bar-fill{animation:none;transform-origin:top left;transition:transform 250ms ease}.cdk-high-contrast-active .mat-progress-bar .mat-progress-bar-fill{border-top:solid 4px}.mat-progress-bar .mat-progress-bar-fill::after{animation:none;content:"";display:inline-block;left:0}.mat-progress-bar[dir=rtl],[dir=rtl] .mat-progress-bar{transform:rotateY(180deg)}.mat-progress-bar[mode=query]{transform:rotateZ(180deg)}.mat-progress-bar[mode=query][dir=rtl],[dir=rtl] .mat-progress-bar[mode=query]{transform:rotateZ(180deg) rotateY(180deg)}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-fill,.mat-progress-bar[mode=query] .mat-progress-bar-fill{transition:none}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary,.mat-progress-bar[mode=query] .mat-progress-bar-primary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-translate 2s infinite linear;left:-145.166611%}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-primary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary,.mat-progress-bar[mode=query] .mat-progress-bar-secondary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-translate 2s infinite linear;left:-54.888891%;display:block}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-secondary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=buffer] .mat-progress-bar-background{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-background-scroll 250ms infinite linear;display:block}.mat-progress-bar._mat-animation-noopable .mat-progress-bar-background,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-buffer,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary.mat-progress-bar-fill::after{animation:none;transition:none}@keyframes mat-progress-bar-primary-indeterminate-translate{0%{transform:translateX(0)}20%{animation-timing-function:cubic-bezier(.5,0,.701732,.495819);transform:translateX(0)}59.15%{animation-timing-function:cubic-bezier(.302435,.381352,.55,.956352);transform:translateX(83.67142%)}100%{transform:translateX(200.611057%)}}@keyframes mat-progress-bar-primary-indeterminate-scale{0%{transform:scaleX(.08)}36.65%{animation-timing-function:cubic-bezier(.334731,.12482,.785844,1);transform:scaleX(.08)}69.15%{animation-timing-function:cubic-bezier(.06,.11,.6,1);transform:scaleX(.661479)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-secondary-indeterminate-translate{0%{animation-timing-function:cubic-bezier(.15,0,.515058,.409685);transform:translateX(0)}25%{animation-timing-function:cubic-bezier(.31033,.284058,.8,.733712);transform:translateX(37.651913%)}48.35%{animation-timing-function:cubic-bezier(.4,.627035,.6,.902026);transform:translateX(84.386165%)}100%{transform:translateX(160.277782%)}}@keyframes mat-progress-bar-secondary-indeterminate-scale{0%{animation-timing-function:cubic-bezier(.15,0,.515058,.409685);transform:scaleX(.08)}19.15%{animation-timing-function:cubic-bezier(.31033,.284058,.8,.733712);transform:scaleX(.457104)}44.15%{animation-timing-function:cubic-bezier(.4,.627035,.6,.902026);transform:scaleX(.72796)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-background-scroll{to{transform:translateX(-8px)}}</style><script charset="utf-8" src="toc-toc-module-es2015.f8531f591ee147aebcc6.js"></script><script charset="utf-8" src="default~code-code-example-module~code-code-tabs-module-es2015.9efcc76d2979a2e605e0.js"></script><script charset="utf-8" src="code-code-example-module-es2015.fa05e6f700453813d256.js"></script><script charset="utf-8" src="code-code-tabs-module-es2015.505e1e0a869946918011.js"></script><script charset="utf-8" src="live-example-live-example-module-es2015.d3b124043392e69f9e97.js"></script><script charset="utf-8" src="assets-js-prettify-js-es2015.ba856648f2dd2d930a9b.js"></script><style>.mat-card{transition:box-shadow 280ms cubic-bezier(.4,0,.2,1);display:block;position:relative;padding:16px;border-radius:4px}._mat-animation-noopable.mat-card{transition:none;animation:none}.mat-card .mat-divider-horizontal{position:absolute;left:0;width:100%}[dir=rtl] .mat-card .mat-divider-horizontal{left:auto;right:0}.mat-card .mat-divider-horizontal.mat-divider-inset{position:static;margin:0}[dir=rtl] .mat-card .mat-divider-horizontal.mat-divider-inset{margin-right:0}.cdk-high-contrast-active .mat-card{outline:solid 1px}.mat-card-actions,.mat-card-content,.mat-card-subtitle{display:block;margin-bottom:16px}.mat-card-title{display:block;margin-bottom:8px}.mat-card-actions{margin-left:-8px;margin-right:-8px;padding:8px 0}.mat-card-actions-align-end{display:flex;justify-content:flex-end}.mat-card-image{width:calc(100% + 32px);margin:0 -16px 16px -16px}.mat-card-footer{display:block;margin:0 -16px -16px -16px}.mat-card-actions .mat-button,.mat-card-actions .mat-raised-button,.mat-card-actions .mat-stroked-button{margin:0 8px}.mat-card-header{display:flex;flex-direction:row}.mat-card-header .mat-card-title{margin-bottom:12px}.mat-card-header-text{margin:0 16px}.mat-card-avatar{height:40px;width:40px;border-radius:50%;flex-shrink:0;object-fit:cover}.mat-card-title-group{display:flex;justify-content:space-between}.mat-card-sm-image{width:80px;height:80px}.mat-card-md-image{width:112px;height:112px}.mat-card-lg-image{width:152px;height:152px}.mat-card-xl-image{width:240px;height:240px;margin:-8px}.mat-card-title-group>.mat-card-xl-image{margin:-8px 0 8px}@media(max-width:599px){.mat-card-title-group{margin:0}.mat-card-xl-image{margin-left:0;margin-right:0}}.mat-card-content>:first-child,.mat-card>:first-child{margin-top:0}.mat-card-content>:last-child:not(.mat-card-footer),.mat-card>:last-child:not(.mat-card-footer){margin-bottom:0}.mat-card-image:first-child{margin-top:-16px;border-top-left-radius:inherit;border-top-right-radius:inherit}.mat-card>.mat-card-actions:last-child{margin-bottom:-8px;padding-bottom:0}.mat-card-actions .mat-button:first-child,.mat-card-actions .mat-raised-button:first-child,.mat-card-actions .mat-stroked-button:first-child{margin-left:0;margin-right:0}.mat-card-subtitle:not(:first-child),.mat-card-title:not(:first-child){margin-top:-4px}.mat-card-header .mat-card-subtitle:not(:first-child){margin-top:-8px}.mat-card>.mat-card-xl-image:first-child{margin-top:-8px}.mat-card>.mat-card-xl-image:last-child{margin-bottom:-8px}</style><style>.mat-tab-group{display:flex;flex-direction:column}.mat-tab-group.mat-tab-group-inverted-header{flex-direction:column-reverse}.mat-tab-label{height:48px;padding:0 24px;cursor:pointer;box-sizing:border-box;opacity:.6;min-width:160px;text-align:center;display:inline-flex;justify-content:center;align-items:center;white-space:nowrap;position:relative}.mat-tab-label:focus{outline:0}.mat-tab-label:focus:not(.mat-tab-disabled){opacity:1}.cdk-high-contrast-active .mat-tab-label:focus{outline:dotted 2px}.mat-tab-label.mat-tab-disabled{cursor:default}.cdk-high-contrast-active .mat-tab-label.mat-tab-disabled{opacity:.5}.mat-tab-label .mat-tab-label-content{display:inline-flex;justify-content:center;align-items:center;white-space:nowrap}.cdk-high-contrast-active .mat-tab-label{opacity:1}@media(max-width:599px){.mat-tab-label{padding:0 12px}}@media(max-width:959px){.mat-tab-label{padding:0 12px}}.mat-tab-group[mat-stretch-tabs]>.mat-tab-header .mat-tab-label{flex-basis:0;flex-grow:1}.mat-tab-body-wrapper{position:relative;overflow:hidden;display:flex;transition:height .5s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable.mat-tab-body-wrapper{transition:none;animation:none}.mat-tab-body{top:0;left:0;right:0;bottom:0;position:absolute;display:block;overflow:hidden;flex-basis:100%}.mat-tab-body.mat-tab-body-active{position:relative;overflow-x:hidden;overflow-y:auto;z-index:1;flex-grow:1}.mat-tab-group.mat-tab-group-dynamic-height .mat-tab-body.mat-tab-body-active{overflow-y:hidden}</style><style>.mat-tab-header{display:flex;overflow:hidden;position:relative;flex-shrink:0}.mat-tab-header-pagination{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:relative;display:none;justify-content:center;align-items:center;min-width:32px;cursor:pointer;z-index:2;-webkit-tap-highlight-color:transparent;touch-action:none}.mat-tab-header-pagination-controls-enabled .mat-tab-header-pagination{display:flex}.mat-tab-header-pagination-before,.mat-tab-header-rtl .mat-tab-header-pagination-after{padding-left:4px}.mat-tab-header-pagination-before .mat-tab-header-pagination-chevron,.mat-tab-header-rtl .mat-tab-header-pagination-after .mat-tab-header-pagination-chevron{transform:rotate(-135deg)}.mat-tab-header-pagination-after,.mat-tab-header-rtl .mat-tab-header-pagination-before{padding-right:4px}.mat-tab-header-pagination-after .mat-tab-header-pagination-chevron,.mat-tab-header-rtl .mat-tab-header-pagination-before .mat-tab-header-pagination-chevron{transform:rotate(45deg)}.mat-tab-header-pagination-chevron{border-style:solid;border-width:2px 2px 0 0;content:"";height:8px;width:8px}.mat-tab-header-pagination-disabled{box-shadow:none;cursor:default}.mat-tab-list{flex-grow:1;position:relative;transition:transform .5s cubic-bezier(.35,0,.25,1)}.mat-ink-bar{position:absolute;bottom:0;height:2px;transition:.5s cubic-bezier(.35,0,.25,1)}._mat-animation-noopable.mat-ink-bar{transition:none;animation:none}.mat-tab-group-inverted-header .mat-ink-bar{bottom:auto;top:0}.cdk-high-contrast-active .mat-ink-bar{outline:solid 2px;height:0}.mat-tab-labels{display:flex}[mat-align-tabs=center] .mat-tab-labels{justify-content:center}[mat-align-tabs=end] .mat-tab-labels{justify-content:flex-end}.mat-tab-label-container{display:flex;flex-grow:1;overflow:hidden;z-index:1}._mat-animation-noopable.mat-tab-list{transition:none;animation:none}.mat-tab-label{height:48px;padding:0 24px;cursor:pointer;box-sizing:border-box;opacity:.6;min-width:160px;text-align:center;display:inline-flex;justify-content:center;align-items:center;white-space:nowrap;position:relative}.mat-tab-label:focus{outline:0}.mat-tab-label:focus:not(.mat-tab-disabled){opacity:1}.cdk-high-contrast-active .mat-tab-label:focus{outline:dotted 2px}.mat-tab-label.mat-tab-disabled{cursor:default}.cdk-high-contrast-active .mat-tab-label.mat-tab-disabled{opacity:.5}.mat-tab-label .mat-tab-label-content{display:inline-flex;justify-content:center;align-items:center;white-space:nowrap}.cdk-high-contrast-active .mat-tab-label{opacity:1}@media(max-width:599px){.mat-tab-label{min-width:72px}}</style><style>.mat-tab-body-content{height:100%;overflow:auto}.mat-tab-group-dynamic-height .mat-tab-body-content{overflow:hidden}</style></head><body><aio-shell ng-version="9.0.0-rc.11" class="aio-notification-hide folder-tutorial mode-stable page-tutorial-toh-pt5 sidenav-open view-SideNav"><div id="top-of-page"></div><mat-toolbar color="primary" class="mat-toolbar app-toolbar no-print mat-primary mat-toolbar-multiple-rows"><mat-toolbar-row class="mat-toolbar-row notification-container"><aio-notification notificationid="survey-february-2019" expirationdate="2019-03-01" class="ng-tns-c22-0 ng-trigger ng-trigger-hideAnimation" style="height:0"><span class="content ng-tns-c22-0"><a href="http://bit.ly/angular-survey-2019" target="_blank" class="ng-tns-c22-0"><mat-icon role="img" svgicon="insert_comment" aria-label="Announcement" class="mat-icon notranslate icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg></mat-icon><span class="message"><b>填写这份《一分钟调查》</b>，帮我们（开发组）做得更好！</span><span class="action-button">去填写</span></a></span><button mat-icon-button="" aria-label="Close" class="close-button ng-tns-c22-0 mat-icon-button mat-button-base"><span class="mat-button-wrapper"><mat-icon role="img" svgicon="close" aria-label="Dismiss notification" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path><path d="M0 0h24v24H0z" fill="none"></path></svg></mat-icon></span><div matripple="" class="mat-ripple mat-button-ripple mat-button-ripple-round"></div><div class="mat-button-focus-overlay"></div></button></aio-notification></mat-toolbar-row><mat-toolbar-row class="mat-toolbar-row"><button mat-button="" title="Docs menu" class="hamburger mat-button mat-button-base"><span class="mat-button-wrapper"><mat-icon role="img" svgicon="menu" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path></svg></mat-icon></span><div matripple="" class="mat-ripple mat-button-ripple"></div><div class="mat-button-focus-overlay"></div></button><a href="/" class="nav-link home"><img src="assets/images/logos/angular/logo-nav@2x.png" width="150" height="40" title="Home" alt="Home" class="ng-star-inserted"></a><aio-top-menu _nghost-ng-docs-c30="" class="ng-star-inserted"><ul _ngcontent-ng-docs-c30="" role="navigation"><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="features" title="特性" target="_self"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">特性</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="docs" title="文档" target="_self"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">文档</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="resources" title="资源" target="_self"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">资源</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="events" title="会议" target="_self"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">会议</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="https://blog.wangke.io/" title="译者汪志成的博客，包括翻译文章和原创文章" target="_blank"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">译者博客</span></a></li><li _ngcontent-ng-docs-c30="" class="ng-star-inserted"><a _ngcontent-ng-docs-c30="" class="nav-link" href="translations/cn/home" title="关于中文版" target="_self"><span _ngcontent-ng-docs-c30="" class="nav-link-inner">关于中文版</span></a></li></ul></aio-top-menu><aio-search-box class="search-container"><input type="search" aria-label="search" placeholder="搜索"></aio-search-box><div class="toolbar-external-icons-container"><a href="https://twitter.com/angular" title="Twitter" aria-label="Angular on twitter"><mat-icon role="img" svgicon="logos:twitter" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 50 59" xmlns="http://www.w3.org/2000/svg"><path d="M50,9.3c-1.8,0.8-3.8,1.4-5.9,1.6c2.1-1.3,3.7-3.3,4.5-5.7c-2,1.2-4.2,2-6.5,2.5c-1.9-2-4.5-3.2-7.5-3.2c-5.7,0-10.3,4.6-10.3,10.3c0,0.8,0.1,1.6,0.3,2.3C16.1,16.7,8.5,12.6,3.5,6.4c-0.9,1.5-1.4,3.3-1.4,5.2c0,3.6,1.8,6.7,4.6,8.5C5,20,3.4,19.6,2,18.8c0,0,0,0.1,0,0.1c0,5,3.5,9.1,8.2,10.1c-0.9,0.2-1.8,0.4-2.7,0.4c-0.7,0-1.3-0.1-1.9-0.2c1.3,4.1,5.1,7,9.6,7.1c-3.5,2.8-7.9,4.4-12.7,4.4c-0.8,0-1.6,0-2.4-0.1c4.5,2.9,9.9,4.6,15.7,4.6c18.9,0,29.2-15.6,29.2-29.2c0-0.4,0-0.9,0-1.3C46.9,13.2,48.6,11.4,50,9.3z"></path></svg></mat-icon></a><a href="https://github.com/angular/angular" title="GitHub" aria-label="Angular on github"><mat-icon role="img" svgicon="logos:github" class="mat-icon notranslate mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 51.8 50.4" xmlns="http://www.w3.org/2000/svg"><path d="M25.9,0.2C11.8,0.2,0.3,11.7,0.3,25.8c0,11.3,7.3,20.9,17.5,24.3c1.3,0.2,1.7-0.6,1.7-1.2c0-0.6,0-2.6,0-4.8c-7.1,1.5-8.6-3-8.6-3c-1.2-3-2.8-3.7-2.8-3.7c-2.3-1.6,0.2-1.6,0.2-1.6c2.6,0.2,3.9,2.6,3.9,2.6c2.3,3.9,6,2.8,7.5,2.1c0.2-1.7,0.9-2.8,1.6-3.4c-5.7-0.6-11.7-2.8-11.7-12.7c0-2.8,1-5.1,2.6-6.9c-0.3-0.7-1.1-3.3,0.3-6.8c0,0,2.1-0.7,7,2.6c2-0.6,4.2-0.9,6.4-0.9c2.2,0,4.4,0.3,6.4,0.9c4.9-3.3,7-2.6,7-2.6c1.4,3.5,0.5,6.1,0.3,6.8c1.6,1.8,2.6,4.1,2.6,6.9c0,9.8-6,12-11.7,12.6c0.9,0.8,1.7,2.4,1.7,4.7c0,3.4,0,6.2,0,7c0,0.7,0.5,1.5,1.8,1.2c10.2-3.4,17.5-13,17.5-24.3C51.5,11.7,40.1,0.2,25.9,0.2z"></path></svg></mat-icon></a></div></mat-toolbar-row></mat-toolbar><mat-sidenav-container role="main" class="mat-drawer-container mat-sidenav-container sidenav-container mat-drawer-transition has-floating-toc"><div class="mat-drawer-backdrop ng-star-inserted"></div><div class="cdk-visually-hidden cdk-focus-trap-anchor" aria-hidden="true"></div><mat-sidenav tabindex="-1" class="mat-drawer mat-sidenav sidenav ng-tns-c18-1 ng-trigger ng-trigger-transform mat-drawer-side ng-star-inserted mat-drawer-opened" style="transform:none;visibility:visible"><div class="mat-drawer-inner-container ng-tns-c18-1"><aio-nav-menu class="ng-tns-c18-1"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="docs" title="Angular 文档简介" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="通过构建第一个 Angular 应用来学习基础知识" aria-pressed="false"><span>快速上手</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start" title="介绍 Angular 的组件模型、模板语法和组件通讯" target="_self"><span>你的第一个应用</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/routing" title="介绍如何使用浏览器的 URL 在组件之间进行路由" target="_self"><span>路由</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/data" title="介绍服务以及如何访问外部数据" target="_self"><span>管理数据</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/forms" title="学习如何使用表单从用户那里获取并管理数据" target="_self"><span>表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="start/deployment" title="通过你的应用放到 Firebase 或自己的服务器上来把它分享给外界" target="_self"><span>部署</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="guide/setup-local" title="使用 Angular CLI 搭建本地开发环境简介" target="_self"><span>搭建环境</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 expanded selected ng-star-inserted" title="Angular 的基本原理" aria-pressed="true"><span>基本原理</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 expanded selected"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="介绍 Angular 应用中的一些基本概念。" aria-pressed="false"><span>Angular 的基本概念</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture" title="Angular 应用中的基本构造块。" target="_self"><span>基本概念简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-modules" title="关于 Angular 模块（NgModules）。" target="_self"><span>模块简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-components" title="关于组件、模板和视图。" target="_self"><span>组件简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-services" title="关于服务与依赖注入。" target="_self"><span>服务与 DI 简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/architecture-next-steps" title="超越基础阶段。" target="_self"><span>后续步骤</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 expanded selected ng-star-inserted" title="英雄指南是这里大量 Angular 范例的基础" aria-pressed="true"><span>英雄指南</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 expanded selected"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial" title="《英雄指南》教程简介" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt0" title="创建应用的外壳" target="_self"><span>应用的“外壳”</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt1" title="第一部分：构建一个简单的英雄编辑器" target="_self"><span>1. 英雄编辑器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt2" title="第二部分：构建一个主从结构的页面，用于展现英雄列表。" target="_self"><span>2. 显示英雄列表</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt3" title="第三部分：把主从结构的视图重构成几个独立的组件。" target="_self"><span>3. 创建特性组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt4" title="第四部分：创建一个可复用的服务来管理英雄数据。" target="_self"><span>4. 添加服务</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 expanded selected ng-star-inserted" style="position:relative" href="tutorial/toh-pt5" title="第五部分：添加 Angular 路由器，并且学习在视图之间导航。" target="_self"><span>5. 添加应用内导航</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="tutorial/toh-pt6" title="第六部分：通过 HTTP 来获取并保存英雄数据。" target="_self"><span>6. 从服务器获取数据</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="通过数据绑定构建动态视图" aria-pressed="false"><span>组件与模板</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/displaying-data" title="属性绑定可以帮助应用把数据显示在界面上" target="_self"><span>显示数据</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/template-syntax" title="学习如何写模板，以便借助数据绑定机制显示数据并响应事件。" target="_self"><span>模板语法</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/user-input" title="用户输入会触发 DOM 事件。Angular 会通过事件绑定来监听那些事件，并把修改后的值传回应用的组件和模型中。" target="_self"><span>用户输入</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/lifecycle-hooks" title="Angular 调用指令和组件的生命周期钩子函数，包括它的创建、变更和销毁时。" target="_self"><span>生命周期钩子</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/component-interaction" title="在不同的指令和组件之间共享信息" target="_self"><span>组件交互</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/component-styles" title="添加专属于某个组件的样式" target="_self"><span>组件样式</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dynamic-component-loader" title="动态加载组件" target="_self"><span>动态组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/elements" title="把组件转换成自定义元素" target="_self"><span>Angular 元素</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/attribute-directives" title="属性型指令把行为添加到现有元素上。" target="_self"><span>属性型指令</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/structural-directives" title="结构型指令可以操纵页面的布局" target="_self"><span>结构型指令</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/pipes" title="管道可以在模板中转换显示的内容。" target="_self"><span>管道</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular 的表单" aria-pressed="false"><span>表单</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/forms-overview" title="表单可以创建集中、高效、引人注目的输入体验。Angular 表单可以协调一组数据绑定控件，跟踪变更，验证输入，并表达错误信息。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/reactive-forms" title="使用 FormBuilder、表单组和表单数组创建响应式表单。" target="_self"><span>响应式表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/forms" title="使用指令和 Angular 模板语法创建模板驱动表单。" target="_self"><span>模板驱动表单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/form-validation" title="验证用户的表单输入" target="_self"><span>表单验证</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dynamic-form" title="使用 FormGroup 渲染动态表单。" target="_self"><span>动态表单</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Observable 与 RxJS" aria-pressed="false"><span>Observable 与 RxJS</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/observables" title="" target="_self"><span>可观察对象(Observable)</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/rx-library" title="" target="_self"><span>RxJS 库</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/observables-in-angular" title="" target="_self"><span>Angular 中的可观察对象</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/practical-observable-usage" title="" target="_self"><span>用法实战</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/comparing-observables" title="" target="_self"><span>与其它技术的比较</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular 中的模块" aria-pressed="false"><span>NgModules</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodules" title="使用 NgModule 让你的应用更高效" target="_self"><span>NgModule 简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-vs-jsmodule" title="JavaScript 模块和 NgModule 之间的差异" target="_self"><span>JS 模块 vs NgModule</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/bootstrapping" title="告诉 Angular 如何在根 &quot;AppModule&quot; 中构造和引导应用。" target="_self"><span>应用的根模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/frequent-ngmodules" title="介绍最常用的 NgModule" target="_self"><span>常用模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/module-types" title="介绍特性模块的几种类型" target="_self"><span>特性模块的分类</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/entry-components" title="关于 Angular 中入口组件的一切" target="_self"><span>入口组件</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/feature-modules" title="创建特性模块，以组织你的代码" target="_self"><span>特性模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/providers" title="服务提供者与 NgModule" target="_self"><span>服务提供者</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/singleton-services" title="创建单例服务" target="_self"><span>单例服务</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/lazy-loading-ngmodules" title="惰性加载模块，以提高应用的性能" target="_self"><span>惰性加载的特性模块</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/sharing-ngmodules" title="共享 NgModule 让你的应用现代化。" target="_self"><span>共享 NgModule</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-api" title="理解 NgModule 的那些细节。" target="_self"><span>NgModule API</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ngmodule-faq" title="回答关于 NgModules 的常见问题。" target="_self"><span>NgModule 常见问题</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="依赖注入：创建并注入各种服务。" aria-pressed="false"><span>依赖注入</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection" title="Angular 的依赖注入系统能够为 Angular 创建的类创建并交付它们所依赖的服务。" target="_self"><span>Angular 依赖注入</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/hierarchical-dependency-injection" title="与组件树平行的注入器树，并支持嵌套的依赖。" target="_self"><span>多级注入器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-providers" title="各种提供者类型的更多知识。" target="_self"><span>DI 提供者</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-in-action" title="依赖注入的使用技巧" target="_self"><span>DI 实战</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/dependency-injection-navtree" title="使用注入器树来查找父组件。" target="_self"><span>浏览组件树</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/http" title="通过 HTTP 协议与远程服务器对话。" target="_self"><span>HttpClient</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/router" title="揭示如何通过 Angular 路由进行基本的屏幕导航。" target="_self"><span>路由与导航</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular 动画系统指南" aria-pressed="false"><span>动画</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/animations" title="Angular 动画的基础技术。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/transition-and-triggers" title="转场与触发器的高级技术。" target="_self"><span>转场与触发器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/complex-animation-sequences" title="复杂的 Angular 动画序列。" target="_self"><span>复杂序列</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/reusable-animations" title="创建可复用的动画。" target="_self"><span>可复用动画</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/route-animations" title="为路由提供转场动画。" target="_self"><span>路由转场动画</span></a></div></aio-nav-item></div></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="把 Angular 用到你的实际工作中的一些技巧" aria-pressed="false"><span>其它技术</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/security" title="Angular 应用开发中的安全技术。" target="_self"><span>安全</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/i18n" title="把应用模板中的文本翻译成多种语言。" target="_self"><span>国际化（i18n）</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/accessibility" title="设计能被所有用户访问的应用" target="_self"><span>无障碍（a11y）</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="Angular Service Worker: 控制应用资源的缓存。" aria-pressed="false"><span>Service Worker 与 PWA</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-intro" title="Angular 对 Service Worker 的实现提升了慢速或不稳定的网络连接下的用户体验。" target="_self"><span>简介</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-getting-started" title="在 CLI 项目中启用 Service Worker，并在浏览器中查看效果。" target="_self"><span>快速上手</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/app-shell" title="在 CLI 项目中启用应用外壳。" target="_self"><span>应用外壳</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-communications" title="那些能让你和 Angular 的 Service Worker 通讯的服务类。" target="_self"><span>与 Service Worker 通讯</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-devops" title="使用 Service Worker 运行应用、管理应用更新、调试以及杀掉正在运行的应用。" target="_self"><span>生产环境下的 Service Worker</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/service-worker-config" title="配置 Service Worker 的缓存行为。" target="_self"><span>Service Worker 配置</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/universal" title="使用 Angular Universal 在服务端渲染 HTML。" target="_self"><span>服务端渲染</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="把 AngularJS 应用增量式的升级到 Angular。" aria-pressed="false"><span>从 AngularJS 升级</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/upgrade" title="把 AngularJS 应用增量式的升级到 Angular。" target="_self"><span>升级步骤</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/upgrade-performance" title="用更灵活的方式把 AngularJS 升级到 Angular。" target="_self"><span>更关注性能的升级方式</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/ajs-quick-reference" title="学习如何把 AngularJS 的概念映射到 Angular 中。" target="_self"><span>AngularJS 与 Angular 的概念对照</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="使用共享库扩展 Angular" aria-pressed="false"><span>开发 Angular 库</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/libraries" title="理解何时以及如何使用和创建库。" target="_self"><span>库概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/using-libraries" title="把已发布的库集成进你的应用中。" target="_self"><span>使用已发布的库</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/creating-libraries" title="通过创建、发布和使用你自己的库来扩展 Angular。" target="_self"><span>创建库</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="理解原理图" aria-pressed="false"><span>原理图（Schematic）</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics" title="理解 Angular 如何使用原理图。" target="_self"><span>原理图概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics-authoring" title="理解原理图的结构。" target="_self"><span>制作原理图</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/schematics-for-libraries" title="使用原理图来把你的库集成进 Angular CLI 中。" target="_self"><span>库的原理图</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/cli-builder" title="使用构建器定制 Angular CLI。" target="_self"><span>CLI 构建器</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/web-worker" title="在 Angular CLI 中使用 Web Worker。" target="_self"><span>Web Worker</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="关于构建、测试和部署的信息" aria-pressed="false"><span>开发工作流</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="理解 AOT 预先编译器。" aria-pressed="false"><span>AOT 预先编译器</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/aot-compiler" title="学习为何以及如何使用预先编译器。" target="_self"><span>预先编译</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/angular-compiler-options" title="配置 AOT 编译。" target="_self"><span>Angular 编译器选项</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/aot-metadata-errors" title="解决 AOT 编译错误。" target="_self"><span>AOT 元数据错误</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/template-typecheck" title="Angular 中的模板类型检查。" target="_self"><span>模板类型检查</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/build" title="构建应用及为应用启动开发服务器。" target="_self"><span>构建与运行</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/bazel" title="如何配置你的环境，以利用 Bazel 进行构建和测试。" target="_self"><span>使用 Bazel 进行构建</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/testing" title="测试 Angular 应用的技巧与实践。" target="_self"><span>测试</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/deployment" title="了解如何部署 Angular 应用。" target="_self"><span>发布</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-2 collapsed ng-star-inserted" title="与开发环境和工具集成起来" aria-pressed="false"><span>开发工具集成</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-2 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-3 collapsed ng-star-inserted" style="position:relative" href="guide/language-service" title="使用 Angular 语言服务加速开发。" target="_self"><span>语言服务</span></a></div></aio-nav-item></div></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="工作空间与项目的结构，及其配置文件。" aria-pressed="false"><span>配置</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/file-structure" title="Angular 工作区在文件系统中是怎样的。" target="_self"><span>项目文件结构</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/workspace-config" title="&quot;angular.json&quot; 包含供 CLI 命令使用的工作区和项目默认配置。" target="_self"><span>工作区配置</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/npm-packages" title="开发期间和运行期间所需的 npm 包的说明。" target="_self"><span>npm 包</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/typescript-configuration" title="给 Angular 开发者的 TypeScript 配置。" target="_self"><span>TypeScript 配置</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/browser-support" title="浏览器支持与腻子脚本指南。" target="_self"><span>浏览器支持</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular 的版本发布实践、更新与升级。" aria-pressed="false"><span>发布信息</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/updating" title="如何把 Angular 应用和库升级到最新版本。" target="_self"><span>保持最新</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/releases" title="Angular 的版本、发布、支持、弃用策略及实践。" target="_self"><span>发布实践</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/updating-to-version-9" title="支持把你的应用从 8 升级到 9。" target="_self"><span>升级到第 9 版</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/deprecations" title="弃用的 Angular API 和特性汇总。" target="_self"><span>弃用清单</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/ivy" title="关于 Angular Ivy 的编译与渲染管道。" target="_self"><span>Angular Ivy</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular 语法、编码、术语汇总。" aria-pressed="false"><span>快捷手册</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/cheatsheet" title="关于 Angular 常用编码技术的快速指南。" target="_self"><span>速查表</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/styleguide" title="写出 Angular 风格的程序" target="_self"><span>风格指南</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="guide/glossary" title="Angular 中最重要的词汇的简要定义。" target="_self"><span>词汇表</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><button type="button" class="vertical-menu-item heading level-1 collapsed ng-star-inserted" title="Angular CLI 命令参考手册。" aria-pressed="false"><span>CLI 命令</span><mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><div class="heading-children level-1 collapsed"><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli" title="CLI 工具介绍、命令、语法" target="_self"><span>概览</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/usage-analytics-gathering" title="管理员如何从用户那里收集使用情况分析。" target="_self"><span>使用情况分析</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/add" title="ng add." target="_self"><span>ng add</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/analytics" title="ng analytics." target="_self"><span>ng analytics</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/build" title="ng build." target="_self"><span>ng build</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/config" title="ng config." target="_self"><span>ng config</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/deploy" title="ng deploy." target="_self"><span>ng deploy</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/doc" title="ng doc." target="_self"><span>ng doc</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/e2e" title="ng e2e." target="_self"><span>ng e2e</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/generate" title="ng generate." target="_self"><span>ng generate</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/help" title="ng help." target="_self"><span>ng help</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/lint" title="ng lint." target="_self"><span>ng lint</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/new" title="ng new." target="_self"><span>ng new</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/run" title="ng run." target="_self"><span>ng run</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/serve" title="ng serve." target="_self"><span>ng serve</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/test" title="ng test." target="_self"><span>ng test</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/update" title="ng update." target="_self"><span>ng update</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/version" title="ng version." target="_self"><span>ng version</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-2 collapsed ng-star-inserted" style="position:relative" href="cli/xi18n" title="ng xi18n." target="_self"><span>ng xi18n</span></a></div></aio-nav-item></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="api" title="关于 Angular 中类和值的详细信息。" target="_self"><span>API 参考手册</span></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><div class="mat-divider ng-star-inserted" style="margin:4px 20px;border-top:1px solid #d3d3d3"></div></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://github.com/ng-docs/ng-docs.github.io/issues" title="github 上的中文互助问答区" target="_blank"><span>互助问答</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://material.angular.cn" title="Angular Material 组件库的中文文档" target="_blank"><span>官方 Material 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://ng.ant.design/" title="Ant Design 的 Angular 实现，服务于企业级后台产品。" target="_blank"><span>ng-zorro 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://devui.design/" title="“华为云” 开源的企业级组件库，核心设计思想是：致简、沉浸、灵活" target="_blank"><span>华为 DevUI 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://ng.mobile.ant.design/" title="Ant Design Mobile 的 Angular 实现，服务于无线产品。" target="_blank"><span>ng-zorro mobile 组件库</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item><aio-nav-item class="ng-star-inserted"><div class="ng-star-inserted"><a class="vertical-menu-item level-1 collapsed ng-star-inserted" style="position:relative" href="https://flutter.cn/" title="Flutter 中文文档站" target="_blank"><span>友站：Flutter 中文</span><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" aria-hidden="true">open_in_new</mat-icon></a></div></aio-nav-item></aio-nav-menu><div class="doc-version ng-tns-c18-1"><aio-select><div class="form-select-menu"><button class="form-select-button"><span><strong></strong></span><span>stable (v9.0.0)</span></button></div></aio-select></div></div></mat-sidenav><div class="cdk-visually-hidden cdk-focus-trap-anchor" aria-hidden="true"></div><mat-sidenav-content cdkscrollable="" class="mat-drawer-content mat-sidenav-content ng-star-inserted" style="margin-left:261px"><main role="main" class="sidenav-content" id="tutorial-toh-pt5"><aio-mode-banner></aio-mode-banner><aio-doc-viewer class=""><div style="opacity:1"><div class="github-links"><a href="https://github.com/angular/angular-cn/edit/aio/aio/content/tutorial/toh-pt5.md?message=docs%3A%20请简述你的修改..." aria-label="提供编辑建议" title="提供编辑建议"><i class="material-icons" aria-hidden="true" role="img">mode_edit</i></a></div><div class="content"><h1 id="add-in-app-navigation-routing" translation-result="on">路由<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-in-app-navigation-routing"><i class="material-icons">link</i></a></h1><aio-toc class="embedded" ng-version="9.0.0-rc.11"><div class="toc-inner no-print collapsed ng-star-inserted"><button type="button" title="Expand/collapse contents" aria-label="Expand/collapse contents" class="toc-heading embedded secondary ng-star-inserted" aria-pressed="false">目录<mat-icon role="img" svgicon="keyboard_arrow_right" class="mat-icon notranslate rotating-icon collapsed mat-icon-no-color" aria-hidden="true"><svg focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"></path></svg></mat-icon></button><ul class="toc-list embedded"><li class="h2 ng-star-inserted" title="添加 AppRoutingModule"><a href="tutorial/toh-pt5#add-the-approutingmodule">添加 <code>AppRoutingModule</code></a></li><li class="h3 ng-star-inserted" title="路由"><a href="tutorial/toh-pt5#routes">路由</a></li><li class="h3 ng-star-inserted" title="RouterModule.forRoot()"><a href="tutorial/toh-pt5#routermoduleforroot"><code>RouterModule.forRoot()</code></a></li><li class="h2 secondary ng-star-inserted" title="添加路由出口 RouterOutlet"><a href="tutorial/toh-pt5#add-routeroutlet">添加路由出口 <code>RouterOutlet</code></a></li><li class="h2 secondary ng-star-inserted" title="添加路由链接 (routerLink)"><a href="tutorial/toh-pt5#add-a-navigation-link-routerlink">添加路由链接 (<code>routerLink</code>)</a></li><li class="h2 secondary ng-star-inserted" title="添加仪表盘视图"><a href="tutorial/toh-pt5#add-a-dashboard-view">添加仪表盘视图</a></li><li class="h3 secondary ng-star-inserted" title="添加仪表盘路由"><a href="tutorial/toh-pt5#add-the-dashboard-route">添加仪表盘路由</a></li><li class="h3 secondary ng-star-inserted" title="添加默认路由"><a href="tutorial/toh-pt5#add-a-default-route">添加默认路由</a></li><li class="h3 secondary ng-star-inserted" title="把仪表盘链接添加到壳组件中"><a href="tutorial/toh-pt5#add-dashboard-link-to-the-shell">把仪表盘链接添加到壳组件中</a></li><li class="h2 secondary ng-star-inserted" title="导航到英雄详情"><a href="tutorial/toh-pt5#navigating-to-hero-details">导航到英雄详情</a></li><li class="h3 secondary ng-star-inserted" title="从 HeroesComponent 中删除英雄详情"><a href="tutorial/toh-pt5#delete-hero-details-from-heroescomponent">从 <code>HeroesComponent</code> 中删除<em>英雄详情</em></a></li><li class="h3 secondary ng-star-inserted" title="添加英雄详情视图"><a href="tutorial/toh-pt5#add-a-hero-detail-route">添加<em>英雄详情</em>视图</a></li><li class="h3 secondary ng-star-inserted" title="DashboardComponent 中的英雄链接"><a href="tutorial/toh-pt5#dashboardcomponent-hero-links"><code>DashboardComponent</code> 中的英雄链接</a></li><li class="h3 secondary ng-star-inserted" title="HeroesComponent 中的英雄链接"><a href="tutorial/toh-pt5#heroescomponent-hero-links"><code>HeroesComponent</code> 中的英雄链接</a></li><li class="h2 secondary ng-star-inserted" title="支持路由的 HeroDetailComponent"><a href="tutorial/toh-pt5#routable-herodetailcomponent">支持路由的 <code>HeroDetailComponent</code></a></li><li class="h3 secondary ng-star-inserted" title="从路由参数中提取 id"><a href="tutorial/toh-pt5#extract-the-id-route-parameter">从路由参数中提取 <code>id</code></a></li><li class="h3 secondary ng-star-inserted" title="添加 HeroService.getHero()"><a href="tutorial/toh-pt5#add-heroservicegethero">添加 <code>HeroService.getHero()</code></a></li><li class="h3 secondary ng-star-inserted" title="回到原路"><a href="tutorial/toh-pt5#find-the-way-back">回到原路</a></li><li class="h2 secondary ng-star-inserted" title="查看最终代码"><a href="tutorial/toh-pt5#final-code-review">查看最终代码</a></li><li class="h2 secondary ng-star-inserted" title="小结"><a href="tutorial/toh-pt5#summary">小结</a></li></ul><button type="button" title="Expand/collapse contents" aria-label="Expand/collapse contents" class="toc-more-items embedded material-icons collapsed ng-star-inserted" aria-pressed="false"></button></div></aio-toc><h1 translation-origin="off" id="add-in-app-navigation-routing">Add in-app navigation (routing)<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-in-app-navigation-routing"><i class="material-icons">link</i></a></h1><p translation-result="on">有一些《英雄指南》的新需求：</p><p translation-origin="off">There are new requirements for the Tour of Heroes app:</p><ul><li><p translation-result="on">添加一个<em>仪表盘</em>视图。</p><p translation-origin="off">Add a <em>Dashboard</em> view.</p></li><li><p translation-result="on">添加在<em>英雄列表</em>和<em>仪表盘</em>视图之间导航的能力。</p><p translation-origin="off">Add the ability to navigate between the <em>Heroes</em> and <em>Dashboard</em> views.</p></li><li><p translation-result="on">无论在哪个视图中点击一个英雄，都会导航到该英雄的详情页。</p><p translation-origin="off">When users click a hero name in either view, navigate to a detail view of the selected hero.</p></li><li><p translation-result="on">在邮件中点击一个<em>深链接</em>，会直接打开一个特定英雄的详情视图。</p><p translation-origin="off">When users click a <em>deep link</em> in an email, open the detail view for a particular hero.</p></li></ul><p translation-result="on">完成时，用户就能像这样在应用中导航：</p><p translation-origin="off">When you’re done, users will be able to navigate the app like this:</p><div class="lightbox"><img src="generated/images/guide/toh/nav-diagram.png" alt="View navigations" width="506" height="433"></div><h2 id="add-the-approutingmodule" translation-result="on">添加 <code>AppRoutingModule</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-the-approutingmodule"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="add-the-approutingmodule">Add the <code>AppRoutingModule</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-the-approutingmodule"><i class="material-icons">link</i></a></h2><p translation-result="on">在 Angular 中，最好在一个独立的顶层模块中加载和配置路由器，它专注于路由功能，然后由根模块 <code>AppModule</code> 导入它。</p><p translation-origin="off">In Angular, the best practice is to load and configure the router in a separate, top-level module that is dedicated to routing and imported by the root <code>AppModule</code>.</p><p translation-result="on">按照惯例，这个模块类的名字叫做 <code>AppRoutingModule</code>，并且位于 <code>src/app</code> 下的 <code>app-routing.module.ts</code> 文件中。</p><p translation-origin="off">By convention, the module class name is <code>AppRoutingModule</code> and it belongs in the <code>app-routing.module.ts</code> in the <code>src/app</code> folder.</p><p translation-result="on">使用 CLI 生成它。</p><p translation-origin="off">Use the CLI to generate it.</p><code-example language="sh" class="code-shell" ng-version="9.0.0-rc.11"><div style="display:none">ng generate module app-routing --flat --module=app</div><aio-code><pre class="lang-sh prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ng generate module app</span><span class="pun">-</span><span class="pln">routing </span><span class="pun">--</span><span class="pln">flat </span><span class="pun">--</span><span class="pln">module</span><span class="pun">=</span><span class="pln">app</span></code>
    </pre></aio-code></code-example><div class="alert is-helpful"><p translation-result="on"><code>--flat</code> 把这个文件放进了 <code>src/app</code> 中，而不是单独的目录中。<br> <code>--module=app</code> 告诉 CLI 把它注册到 <code>AppModule</code> 的 <code>imports</code> 数组中。</p><p translation-origin="off"><code>--flat</code> puts the file in <code>src/app</code> instead of its own folder.<br> <code>--module=app</code> tells the CLI to register it in the <code>imports</code> array of the <code>AppModule</code>.</p></div><p translation-result="on">生成的文件是这样的：</p><p translation-origin="off">The generated file looks like this:</p><code-example path="toh-pt5/src/app/app-routing.module.0.ts" header="src/app/app-routing.module.ts (generated)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/NgModule" class="code-anchor">NgModule</a> } from '@angular/core'; import { <a href="api/common/CommonModule" class="code-anchor">CommonModule</a> } from '@angular/common'; @<a href="api/core/NgModule" class="code-anchor">NgModule</a>({ imports: [ <a href="api/common/CommonModule" class="code-anchor">CommonModule</a> ], declarations: [] }) export class AppRoutingModule { }</div><header class="ng-star-inserted">src/app/app-routing.module.ts (generated)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (generated)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/NgModule" class="code-anchor"><span class="typ">NgModule</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/common/CommonModule" class="code-anchor"><span class="typ">CommonModule</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/common'</span><span class="pun">;</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/NgModule" class="code-anchor"><span class="lit">NgModule</span></a><span class="pun">({</span><span class="pln">
  imports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
    </span><a href="api/common/CommonModule" class="code-anchor"><span class="typ">CommonModule</span></a><span class="pln">
  </span><span class="pun">],</span><span class="pln">
  declarations</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">AppRoutingModule</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">把它替换为如下代码：</p><p translation-origin="off">Replace it with the following:</p><code-example path="toh-pt5/src/app/app-routing.module.1.ts" header="src/app/app-routing.module.ts (updated)" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/core/NgModule" class="code-anchor">NgModule</a> } from '@angular/core'; import { <a href="api/router/RouterModule" class="code-anchor">RouterModule</a>, <a href="api/router/Routes" class="code-anchor">Routes</a> } from '@angular/router'; import { HeroesComponent } from './heroes/heroes.component'; const routes: <a href="api/router/Routes" class="code-anchor">Routes</a> = [ { path: 'heroes', component: HeroesComponent } ]; @<a href="api/core/NgModule" class="code-anchor">NgModule</a>({ imports: [RouterModule.forRoot(routes)], exports: [<a href="api/router/RouterModule" class="code-anchor">RouterModule</a>] }) export class AppRoutingModule { }</div><header class="ng-star-inserted">src/app/app-routing.module.ts (updated)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (updated)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/NgModule" class="code-anchor"><span class="typ">NgModule</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/router/RouterModule" class="code-anchor"><span class="typ">RouterModule</span></a><span class="pun">,</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/router'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./heroes/heroes.component'</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> routes</span><span class="pun">:</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'heroes'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">
</span><span class="pun">];</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/NgModule" class="code-anchor"><span class="lit">NgModule</span></a><span class="pun">({</span><span class="pln">
  imports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="typ">RouterModule</span><span class="pun">.</span><span class="pln">forRoot</span><span class="pun">(</span><span class="pln">routes</span><span class="pun">)],</span><span class="pln">
  exports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><a href="api/router/RouterModule" class="code-anchor"><span class="typ">RouterModule</span></a><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">AppRoutingModule</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">首先，<code>AppRoutingModule</code> 会导入<code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> 和 <code><a href="api/router/Routes" class="code-anchor">Routes</a></code>，以便该应用具有路由功能。配置好路由后，接着导入 <code>HeroesComponent</code>，它将告诉路由器要去什么地方。</p><p translation-origin="off">First, <code>AppRoutingModule</code> imports <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> and <code><a href="api/router/Routes" class="code-anchor">Routes</a></code> so the app can have routing functionality. The next import, <code>HeroesComponent</code>, will give the Router somewhere to go once you configure the routes.</p><p translation-result="on">注意，对 <code><a href="api/common/CommonModule" class="code-anchor">CommonModule</a></code> 的引用和 <code>declarations</code> 数组不是必要的，因此它们不再是 <code>AppRoutingModule</code> 的一部分。以下各节将详细介绍 <code>AppRoutingModule</code> 的其余部分。</p><p translation-origin="off">Notice that the <code><a href="api/common/CommonModule" class="code-anchor">CommonModule</a></code> references and <code>declarations</code> array are unnecessary, so are no longer part of <code>AppRoutingModule</code>. The following sections explain the rest of the <code>AppRoutingModule</code> in more detail.</p><h3 id="routes" translation-result="on">路由<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#routes"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="routes">Routes<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#routes"><i class="material-icons">link</i></a></h3><p translation-result="on">该文件的下一部分是你的路由配置。 <em>Routes</em> 告诉路由器，当用户单击链接或将 URL 粘贴进浏览器地址栏时要显示哪个视图。</p><p translation-origin="off">The next part of the file is where you configure your routes. <em>Routes</em> tell the Router which view to display when a user clicks a link or pastes a URL into the browser address bar.</p><p translation-result="on">由于 <code>AppRoutingModule</code> 已经导入了 <code>HeroesComponent</code>，因此你可以直接在 <code>routes</code> 数组中使用它：</p><p translation-origin="off">Since <code>AppRoutingModule</code> already imports <code>HeroesComponent</code>, you can use it in the <code>routes</code> array:</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts" region="heroes-route" ng-version="9.0.0-rc.11"><div style="display:none">const routes: <a href="api/router/Routes" class="code-anchor">Routes</a> = [ { path: 'heroes', component: HeroesComponent } ];</div><header class="ng-star-inserted">src/app/app-routing.module.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">const</span><span class="pln"> routes</span><span class="pun">:</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'heroes'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">
</span><span class="pun">];</span></code>
    </pre></aio-code></code-example><p translation-result="on">典型的 Angular <code><a href="api/router/Route" class="code-anchor">Route</a></code> 具有两个属性：</p><p translation-origin="off">A typical Angular <code><a href="api/router/Route" class="code-anchor">Route</a></code> has two properties:</p><ul><li><p translation-result="on"><code>path</code>: 用来匹配浏览器地址栏中 URL 的字符串。</p><p translation-origin="off"><code>path</code>: a string that matches the URL in the browser address bar.</p></li><li><p translation-result="on"><code>component</code>: 导航到该路由时，路由器应该创建的组件。</p><p translation-origin="off"><code>component</code>: the component that the router should create when navigating to this route.</p></li></ul><p translation-result="on">这会告诉路由器把该 URL 与 <code>path：'heroes'</code> 匹配。 如果网址类似于 <code>localhost:4200/heroes</code> 就显示 <code>HeroesComponent</code>。</p><p translation-origin="off">This tells the router to match that URL to <code>path: 'heroes'</code> and display the <code>HeroesComponent</code> when the URL is something like <code>localhost:4200/heroes</code>.</p><h3 id="routermoduleforroot"><code><a href="api/router/RouterModule#forRoot" class="code-anchor">RouterModule.forRoot()</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#routermoduleforroot"><i class="material-icons">link</i></a></h3><p translation-result="on"><code>@<a href="api/core/NgModule" class="code-anchor">NgModule</a></code> 元数据会初始化路由器，并开始监听浏览器地址的变化。</p><p translation-origin="off">The <code>@<a href="api/core/NgModule" class="code-anchor">NgModule</a></code> metadata initializes the router and starts it listening for browser location changes.</p><p translation-result="on">下面的代码行将 <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> 添加到 <code>AppRoutingModule</code> 的 <code>imports</code> 数组中，同时通过调用 <code><a href="api/router/RouterModule#forRoot" class="code-anchor">RouterModule.forRoot()</a></code> 来用这些 <code>routes</code> 配置它：</p><p translation-origin="off">The following line adds the <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> to the <code>AppRoutingModule</code> <code>imports</code> array and configures it with the <code>routes</code> in one step by calling <code><a href="api/router/RouterModule#forRoot" class="code-anchor">RouterModule.forRoot()</a></code>:</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts" region="ngmodule-imports" ng-version="9.0.0-rc.11"><div style="display:none">imports: [ RouterModule.forRoot(routes) ],</div><header class="ng-star-inserted">src/app/app-routing.module.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">imports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><span class="typ">RouterModule</span><span class="pun">.</span><span class="pln">forRoot</span><span class="pun">(</span><span class="pln">routes</span><span class="pun">)</span><span class="pln"> </span><span class="pun">],</span></code>
    </pre></aio-code></code-example><div class="alert is-helpful"><p translation-result="on">这个方法之所以叫 <code><a href="api/router/RouterModule#forRoot" class="code-anchor">forRoot()</a></code>，是因为你要在应用的顶层配置这个路由器。 <code><a href="api/router/RouterModule#forRoot" class="code-anchor">forRoot()</a></code> 方法会提供路由所需的服务提供者和指令，还会基于浏览器的当前 URL 执行首次导航。</p><p translation-origin="off">The method is called <code><a href="api/router/RouterModule#forRoot" class="code-anchor">forRoot()</a></code> because you configure the router at the application's root level. The <code><a href="api/router/RouterModule#forRoot" class="code-anchor">forRoot()</a></code> method supplies the service providers and directives needed for routing, and performs the initial navigation based on the current browser URL.</p></div><p translation-result="on">接下来，<code>AppRoutingModule</code> 导出 <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code>，以便它在整个应用程序中生效。</p><p translation-origin="off">Next, <code>AppRoutingModule</code> exports <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> so it will be available throughout the app.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts (exports array)" region="export-routermodule" ng-version="9.0.0-rc.11"><div style="display:none">exports: [ <a href="api/router/RouterModule" class="code-anchor">RouterModule</a> ]</div><header class="ng-star-inserted">src/app/app-routing.module.ts (exports array)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (exports array)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">exports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><a href="api/router/RouterModule" class="code-anchor"><span class="typ">RouterModule</span></a><span class="pln"> </span><span class="pun">]</span></code>
    </pre></aio-code></code-example><h2 id="add-routeroutlet" translation-result="on">添加路由出口 <code><a href="api/router/RouterOutlet" class="code-anchor">RouterOutlet</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-routeroutlet"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="add-routeroutlet">Add <code><a href="api/router/RouterOutlet" class="code-anchor">RouterOutlet</a></code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-routeroutlet"><i class="material-icons">link</i></a></h2><p translation-result="on">打开 <code>AppComponent</code> 的模板，把 <code>&lt;app-heroes&gt;</code> 元素替换为 <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> 元素。</p><p translation-origin="off">Open the <code>AppComponent</code> template and replace the <code>&lt;app-heroes&gt;</code> element with a <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> element.</p><code-example path="toh-pt5/src/app/app.component.html" region="outlet" header="src/app/app.component.html (router-outlet)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;h1&gt;{{title}}&lt;/h1&gt; &lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;&lt;/<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt; &lt;app-messages&gt;&lt;/app-messages&gt;</div><header class="ng-star-inserted">src/app/app.component.html (router-outlet)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html (router-outlet)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h1&gt;</span><span class="pln">{{title}}</span><span class="tag">&lt;/h1&gt;</span><span class="pln">
</span><span class="tag">&lt;</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;&lt;/</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;app-messages&gt;&lt;/app-messages&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>AppComponent</code> 的模板不再需要 <code>&lt;app-heroes&gt;</code>，因为只有当用户导航到这里时，才需要显示 <code>HeroesComponent</code>。</p><p translation-origin="off">The <code>AppComponent</code> template no longer needs <code>&lt;app-heroes&gt;</code> because the app will only display the <code>HeroesComponent</code> when the user navigates to it.</p><p translation-result="on"><code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> 会告诉路由器要在哪里显示路由的视图。</p><p translation-origin="off">The <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> tells the router where to display routed views.</p><div class="alert is-helpful"><p translation-result="on">能在 <code>AppComponent</code> 中使用 <code><a href="api/router/RouterOutlet" class="code-anchor">RouterOutlet</a></code>，是因为 <code>AppModule</code> 导入了 <code>AppRoutingModule</code>，而 <code>AppRoutingModule</code> 中导出了 <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code>。 在本教程开始时你运行的那个 <code>ng generate</code> 命令添加了这个导入，是因为 <code>--module=app</code> 标志。如果你手动创建 <code>app-routing.module.ts</code> 或使用了 CLI 之外的工具，你就要把 <code>AppRoutingModule</code> 导入到 <code>app.module.ts</code> 中，并且把它添加到 <code><a href="api/core/NgModule" class="code-anchor">NgModule</a></code> 的 <code>imports</code> 数组中。</p><p translation-origin="off">The <code><a href="api/router/RouterOutlet" class="code-anchor">RouterOutlet</a></code> is one of the router directives that became available to the <code>AppComponent</code> because <code>AppModule</code> imports <code>AppRoutingModule</code> which exported <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code>. The <code>ng generate</code> command you ran at the start of this tutorial added this import because of the <code>--module=app</code> flag. If you manually created <code>app-routing.module.ts</code> or used a tool other than the CLI to do so, you'll need to import <code>AppRoutingModule</code> into <code>app.module.ts</code> and add it to the <code>imports</code> array of the <code><a href="api/core/NgModule" class="code-anchor">NgModule</a></code>.</p></div><h4 id="try-it" translation-result="on">试试看<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#try-it"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="try-it">Try it<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#try-it"><i class="material-icons">link</i></a></h4><p translation-result="on">你的 CLI 命令应该仍在运行吧。</p><p translation-origin="off">You should still be running with this CLI command.</p><code-example language="sh" class="code-shell" ng-version="9.0.0-rc.11"><div style="display:none">ng serve</div><aio-code><pre class="lang-sh prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ng serve</span></code>
    </pre></aio-code></code-example><p translation-result="on">浏览器应该刷新，并显示着应用的标题，但是没有显示英雄列表。</p><p translation-origin="off">The browser should refresh and display the app title but not the list of heroes.</p><p translation-result="on">看看浏览器的地址栏。 URL 是以 <code>/</code> 结尾的。 而到 <code>HeroesComponent</code> 的路由路径是 <code>/heroes</code>。</p><p translation-origin="off">Look at the browser's address bar. The URL ends in <code>/</code>. The route path to <code>HeroesComponent</code> is <code>/heroes</code>.</p><p translation-result="on">在地址栏中把 <code>/heroes</code> 追加到 URL 后面。你应该能看到熟悉的主从结构的英雄显示界面。</p><p translation-origin="off">Append <code>/heroes</code> to the URL in the browser address bar. You should see the familiar heroes master/detail view.</p><a id="routerlink"></a><h2 id="add-a-navigation-link-routerlink" translation-result="on">添加路由链接 (<code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code>)<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-navigation-link-routerlink"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="add-a-navigation-link-routerlink">Add a navigation link (<code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code>)<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-navigation-link-routerlink"><i class="material-icons">link</i></a></h2><p translation-result="on">理想情况下，用户应该能通过点击链接进行导航，而不用被迫把路由的 URL 粘贴到地址栏。</p><p translation-origin="off">Ideally, users should be able to click a link to navigate rather than pasting a route URL into the address bar.</p><p translation-result="on">添加一个 <code>&lt;nav&gt;</code> 元素，并在其中放一个链接 <code>&lt;a&gt;</code> 元素，当点击它时，就会触发一个到 <code>HeroesComponent</code> 的导航。 修改过的 <code>AppComponent</code> 模板如下：</p><p translation-origin="off">Add a <code>&lt;nav&gt;</code> element and, within that, an anchor element that, when clicked, triggers navigation to the <code>HeroesComponent</code>. The revised <code>AppComponent</code> template looks like this:</p><code-example path="toh-pt5/src/app/app.component.html" region="heroes" header="src/app/app.component.html (heroes RouterLink)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;h1&gt;{{title}}&lt;/h1&gt; &lt;nav&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/heroes"&gt;Heroes&lt;/a&gt; &lt;/nav&gt; &lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;&lt;/<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt; &lt;app-messages&gt;&lt;/app-messages&gt;</div><header class="ng-star-inserted">src/app/app.component.html (heroes RouterLink)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html (heroes RouterLink)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h1&gt;</span><span class="pln">{{title}}</span><span class="tag">&lt;/h1&gt;</span><span class="pln">
</span><span class="tag">&lt;nav&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/heroes"</span><span class="tag">&gt;</span><span class="pln">Heroes</span><span class="tag">&lt;/a&gt;</span><span class="pln">
</span><span class="tag">&lt;/nav&gt;</span><span class="pln">
</span><span class="tag">&lt;</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;&lt;/</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;app-messages&gt;&lt;/app-messages&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on"><a href="tutorial/toh-pt5#routerlink"><code>routerLink</code> 属性</a>的值为 <code>"/heroes"</code>，路由器会用它来匹配出指向 <code>HeroesComponent</code> 的路由。 <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> 是 <a href="/api/router/RouterLink"><code>RouterLink</code> 指令</a>的选择器，它会把用户的点击转换为路由器的导航操作。 它是 <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code> 中的另一个公共指令。</p><p translation-origin="off">A <a href="tutorial/toh-pt5#routerlink"><code>routerLink</code> attribute</a> is set to <code>"/heroes"</code>, the string that the router matches to the route to <code>HeroesComponent</code>. The <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> is the selector for the <a href="/api/router/RouterLink"><code>RouterLink</code> directive</a> that turns user clicks into router navigations. It's another of the public directives in the <code><a href="api/router/RouterModule" class="code-anchor">RouterModule</a></code>.</p><p translation-result="on">刷新浏览器，显示出了应用的标题和指向英雄列表的链接，但并没有显示英雄列表。</p><p translation-origin="off">The browser refreshes and displays the app title and heroes link, but not the heroes list.</p><p translation-result="on">点击这个链接。地址栏变成了 <code>/heroes</code>，并且显示出了英雄列表。</p><p translation-origin="off">Click the link. The address bar updates to <code>/heroes</code> and the list of heroes appears.</p><div class="alert is-helpful"><p translation-result="on">从下面的 <a href="tutorial/toh-pt5#appcomponent">最终代码</a>中把私有 CSS 样式添加到 <code>app.component.css</code> 中，可以让导航链接变得更好看一点。</p><p translation-origin="off">Make this and future navigation links look better by adding private CSS styles to <code>app.component.css</code> as listed in the <a href="tutorial/toh-pt5#appcomponent">final code review</a> below.</p></div><h2 id="add-a-dashboard-view" translation-result="on">添加仪表盘视图<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-dashboard-view"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="add-a-dashboard-view">Add a dashboard view<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-dashboard-view"><i class="material-icons">link</i></a></h2><p translation-result="on">当有多个视图时，路由会更有价值。不过目前还只有一个英雄列表视图。</p><p translation-origin="off">Routing makes more sense when there are multiple views. So far there's only the heroes view.</p><p translation-result="on">使用 CLI 添加一个 <code>DashboardComponent</code>：</p><p translation-origin="off">Add a <code>DashboardComponent</code> using the CLI:</p><code-example language="sh" class="code-shell" ng-version="9.0.0-rc.11"><div style="display:none">ng generate component dashboard</div><aio-code><pre class="lang-sh prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ng generate component dashboard</span></code>
    </pre></aio-code></code-example><p translation-result="on">CLI 生成了 <code>DashboardComponent</code> 的相关文件，并把它声明到 <code>AppModule</code> 中。</p><p translation-origin="off">The CLI generates the files for the <code>DashboardComponent</code> and declares it in <code>AppModule</code>.</p><p translation-result="on">把这三个文件中的内容改成这样：</p><p translation-origin="off">Replace the default file content in these three files as follows:</p><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/dashboard/dashboard.component.html" path="toh-pt5/src/app/dashboard/dashboard.component.1.html">&lt;h3&gt;Top Heroes&lt;/h3&gt; &lt;div class="grid grid-pad"&gt; &lt;a *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes" class="col-1-4"&gt; &lt;div class="module hero"&gt; &lt;h4&gt;{{hero.name}}&lt;/h4&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt;</code-pane><code-pane header="src/app/dashboard/dashboard.component.ts" path="toh-pt5/src/app/dashboard/dashboard.component.ts">import { <a href="api/core/Component" class="code-anchor">Component</a>, <a href="api/core/OnInit" class="code-anchor">OnInit</a> } from '@angular/core'; import { Hero } from '../hero'; import { HeroService } from '../hero.service'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-dashboard', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './dashboard.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: [ './dashboard.component.css' ] }) export class DashboardComponent implements <a href="api/core/OnInit" class="code-anchor">OnInit</a> { heroes: Hero[] = []; constructor(private heroService: HeroService) { } ngOnInit() { this.getHeroes(); } getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes =&gt; this.heroes = heroes.slice(1, 5)); } }</code-pane><code-pane header="src/app/dashboard/dashboard.component.css" path="toh-pt5/src/app/dashboard/dashboard.component.css">/* DashboardComponent's private CSS styles */ [class*='col-'] { float: left; padding-right: 20px; padding-bottom: 20px; } [class*='col-']:last-of-type { padding-right: 0; } a { text-decoration: none; } *, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } h3 { text-align: center; margin-bottom: 0; } h4 { <a href="api/router/Scroll#position" class="code-anchor">position</a>: relative; } .grid { margin: 0; } .col-1-4 { width: 25%; } .module { padding: 20px; text-align: center; color: #eee; max-height: 120px; min-width: 120px; background-color: #3f525c; border-radius: 2px; } .module:hover { background-color: #eee; cursor: pointer; color: #607d8b; } .grid-pad { padding: 10px 0; } .grid-pad &gt; [class*='col-']:last-of-type { padding-right: 20px; } @media (max-width: 600px) { .module { font-size: 10px; max-height: 75px; } } @media (max-width: 1024px) { .grid { margin: 0; } .module { min-width: 60px; } }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header mat-tab-header-pagination-controls-enabled"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-0-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-0-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.html</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-0-1" tabindex="-1" aria-posinset="2" aria-setsize="3" aria-controls="mat-tab-content-0-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-0-2" tabindex="-1" aria-posinset="3" aria-setsize="3" aria-controls="mat-tab-content-0-2" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.css</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:338px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-2 mat-tab-body-active ng-star-inserted" id="mat-tab-content-0-0" aria-labelledby="mat-tab-label-0-0"><div class="mat-tab-body-content ng-tns-c50-2 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/dashboard/dashboard.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h3&gt;</span><span class="pln">Top Heroes</span><span class="tag">&lt;/h3&gt;</span><span class="pln">
</span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"grid grid-pad"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"col-1-4"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"module hero"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;h4&gt;</span><span class="pln">{{hero.name}}</span><span class="tag">&lt;/h4&gt;</span><span class="pln">
    </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;/a&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-3 ng-star-inserted" id="mat-tab-content-0-1" aria-labelledby="mat-tab-label-0-1"><div class="mat-tab-body-content ng-tns-c50-3 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-4 ng-star-inserted" id="mat-tab-content-0-2" aria-labelledby="mat-tab-label-0-2"><div class="mat-tab-body-content ng-tns-c50-4 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><p translation-result="on">这个<em>模板</em>用来表示由英雄名字链接组成的一个阵列。</p><p translation-origin="off">The <em>template</em> presents a grid of hero name links.</p><ul><li><p translation-result="on"> <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> 复写器为组件的 <code>heroes</code> 数组中的每个条目创建了一个链接。</p><p translation-origin="off">The <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> repeater creates as many links as are in the component's <code>heroes</code> array.</p></li><li><p translation-result="on">这些链接被 <code>dashboard.component.css</code> 中的样式格式化成了一些色块。</p><p translation-origin="off">The links are styled as colored blocks by the <code>dashboard.component.css</code>.</p></li><li><p translation-result="on">这些链接还没有指向任何地方，但<a href="tutorial/toh-pt5#hero-details">很快就会了</a>。</p><p translation-origin="off">The links don't go anywhere yet but <a href="tutorial/toh-pt5#hero-details">they will shortly</a>.</p></li></ul><p translation-result="on">这个<em>类</em>和 <code>HeroesComponent</code> 类很像。</p><p translation-origin="off">The <em>class</em> is similar to the <code>HeroesComponent</code> class.</p><ul><li><p translation-result="on">它定义了一个 <code>heroes</code> 数组属性。</p><p translation-origin="off">It defines a <code>heroes</code> array property.</p></li><li><p translation-result="on">它的构造函数希望 Angular 把 <code>HeroService</code> 注入到私有的 <code>heroService</code> 属性中。</p><p translation-origin="off">The constructor expects Angular to inject the <code>HeroService</code> into a private <code>heroService</code> property.</p></li><li><p translation-result="on">在 <code>ngOnInit()</code> 生命周期钩子中调用 <code>getHeroes()</code>。</p><p translation-origin="off">The <code>ngOnInit()</code> lifecycle hook calls <code>getHeroes()</code>.</p></li></ul><p translation-result="on">这个 <code>getHeroes()</code> 函数会截取第 2 到 第 5 位英雄，也就是说只返回四个顶层英雄（第二，第三，第四和第五）。</p><p translation-origin="off">This <code>getHeroes()</code> returns the sliced list of heroes at positions 1 and 5, returning only four of the Top Heroes (2nd, 3rd, 4th, and 5th).</p><code-example path="toh-pt5/src/app/dashboard/dashboard.component.ts" header="src/app/dashboard/dashboard.component.ts" region="getHeroes" ng-version="9.0.0-rc.11"><div style="display:none">getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes =&gt; this.heroes = heroes.slice(1, 5)); }</div><header class="ng-star-inserted">src/app/dashboard/dashboard.component.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/dashboard/dashboard.component.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">getHeroes</span><span class="pun">():</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">heroService</span><span class="pun">.</span><span class="pln">getHeroes</span><span class="pun">()</span><span class="pln">
    </span><span class="pun">.</span><span class="pln">subscribe</span><span class="pun">(</span><span class="pln">heroes </span><span class="pun">=&gt;</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">heroes </span><span class="pun">=</span><span class="pln"> heroes</span><span class="pun">.</span><span class="pln">slice</span><span class="pun">(</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">5</span><span class="pun">));</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><h3 id="add-the-dashboard-route" translation-result="on">添加仪表盘路由<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-the-dashboard-route"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="add-the-dashboard-route">Add the dashboard route<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-the-dashboard-route"><i class="material-icons">link</i></a></h3><p translation-result="on">要导航到仪表盘，路由器中就需要一个相应的路由。</p><p translation-origin="off">To navigate to the dashboard, the router needs an appropriate route.</p><p translation-result="on">把 <code>DashboardComponent</code> 导入到 <code>AppRoutingModule</code> 中。</p><p translation-origin="off">Import the <code>DashboardComponent</code> in the <code>AppRoutingModule</code>.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" region="import-dashboard" header="src/app/app-routing.module.ts (import DashboardComponent)" ng-version="9.0.0-rc.11"><div style="display:none">import { DashboardComponent } from './dashboard/dashboard.component';</div><header class="ng-star-inserted">src/app/app-routing.module.ts (import DashboardComponent)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (import DashboardComponent)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">DashboardComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">   </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./dashboard/dashboard.component'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><p translation-result="on">把一个指向 <code>DashboardComponent</code> 的路由添加到 <code>AppRoutingModule.routes</code> 数组中。</p><p translation-origin="off">Add a route to the <code>AppRoutingModule.routes</code> array that matches a path to the <code>DashboardComponent</code>.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts" region="dashboard-route" ng-version="9.0.0-rc.11"><div style="display:none">{ path: 'dashboard', component: DashboardComponent },</div><header class="ng-star-inserted">src/app/app-routing.module.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">DashboardComponent</span><span class="pln"> </span><span class="pun">},</span></code>
    </pre></aio-code></code-example><h3 id="add-a-default-route" translation-result="on">添加默认路由<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-default-route"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="add-a-default-route">Add a default route<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-default-route"><i class="material-icons">link</i></a></h3><p translation-result="on">当应用启动时，浏览器的地址栏指向了网站的根路径。 它没有匹配到任何现存路由，因此路由器也不会导航到任何地方。 <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> 下方是空白的。</p><p translation-origin="off">When the app starts, the browser's address bar points to the web site's root. That doesn't match any existing route so the router doesn't navigate anywhere. The space below the <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> is blank.</p><p translation-result="on">要让应用自动导航到这个仪表盘，请把下列路由添加到 <code>AppRoutingModule.Routes</code> 数组中。</p><p translation-origin="off">To make the app navigate to the dashboard automatically, add the following route to the <code>AppRoutingModule.Routes</code> array.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts" region="redirect-route" ng-version="9.0.0-rc.11"><div style="display:none">{ path: '', <a href="api/router/Route#redirectTo" class="code-anchor">redirectTo</a>: '/dashboard', <a href="api/router/Route#pathMatch" class="code-anchor">pathMatch</a>: '<a href="api/core/Version#full" class="code-anchor">full</a>' },</div><header class="ng-star-inserted">src/app/app-routing.module.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#redirectTo" class="code-anchor"><span class="pln">redirectTo</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'/dashboard'</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#pathMatch" class="code-anchor"><span class="pln">pathMatch</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'</span><a href="api/core/Version#full" class="code-anchor"><span class="str">full</span></a><span class="str">'</span><span class="pln"> </span><span class="pun">},</span></code>
    </pre></aio-code></code-example><p translation-result="on">这个路由会把一个与空路径“完全匹配”的 URL 重定向到路径为 <code>'/dashboard'</code> 的路由。</p><p translation-origin="off">This route redirects a URL that fully matches the empty path to the route whose path is <code>'/dashboard'</code>.</p><p translation-result="on">浏览器刷新之后，路由器加载了 <code>DashboardComponent</code>，并且浏览器的地址栏会显示出 <code>/dashboard</code> 这个 URL。</p><p translation-origin="off">After the browser refreshes, the router loads the <code>DashboardComponent</code> and the browser address bar shows the <code>/dashboard</code> URL.</p><h3 id="add-dashboard-link-to-the-shell" translation-result="on">把仪表盘链接添加到壳组件中<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-dashboard-link-to-the-shell"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="add-dashboard-link-to-the-shell">Add dashboard link to the shell<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-dashboard-link-to-the-shell"><i class="material-icons">link</i></a></h3><p translation-result="on">应该允许用户通过点击页面顶部导航区的各个链接在 <code>DashboardComponent</code> 和 <code>HeroesComponent</code> 之间来回导航。</p><p translation-origin="off">The user should be able to navigate back and forth between the <code>DashboardComponent</code> and the <code>HeroesComponent</code> by clicking links in the navigation area near the top of the page.</p><p translation-result="on">把仪表盘的导航链接添加到壳组件 <code>AppComponent</code> 的模板中，就放在 <em>Heroes</em> 链接的前面。</p><p translation-origin="off">Add a dashboard navigation link to the <code>AppComponent</code> shell template, just above the <em>Heroes</em> link.</p><code-example path="toh-pt5/src/app/app.component.html" header="src/app/app.component.html" ng-version="9.0.0-rc.11"><div style="display:none">&lt;h1&gt;{{title}}&lt;/h1&gt; &lt;nav&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/dashboard"&gt;Dashboard&lt;/a&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/heroes"&gt;Heroes&lt;/a&gt; &lt;/nav&gt; &lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;&lt;/<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt; &lt;app-messages&gt;&lt;/app-messages&gt;</div><header class="ng-star-inserted">src/app/app.component.html</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h1&gt;</span><span class="pln">{{title}}</span><span class="tag">&lt;/h1&gt;</span><span class="pln">
</span><span class="tag">&lt;nav&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/dashboard"</span><span class="tag">&gt;</span><span class="pln">Dashboard</span><span class="tag">&lt;/a&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/heroes"</span><span class="tag">&gt;</span><span class="pln">Heroes</span><span class="tag">&lt;/a&gt;</span><span class="pln">
</span><span class="tag">&lt;/nav&gt;</span><span class="pln">
</span><span class="tag">&lt;</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;&lt;/</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;app-messages&gt;&lt;/app-messages&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">刷新浏览器，你就能通过点击这些链接在这两个视图之间自由导航了。</p><p translation-origin="off">After the browser refreshes you can navigate freely between the two views by clicking the links.</p><a id="hero-details"></a><h2 id="navigating-to-hero-details" translation-result="on">导航到英雄详情<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#navigating-to-hero-details"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="navigating-to-hero-details">Navigating to hero details<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#navigating-to-hero-details"><i class="material-icons">link</i></a></h2><p translation-result="on"><code>HeroDetailComponent</code> 可以显示所选英雄的详情。 此刻，<code>HeroDetailsComponent</code> 只能在 <code>HeroesComponent</code> 的底部看到。</p><p translation-origin="off">The <code>HeroDetailsComponent</code> displays details of a selected hero. At the moment the <code>HeroDetailsComponent</code> is only visible at the bottom of the <code>HeroesComponent</code></p><p translation-result="on">用户应该能通过三种途径看到这些详情。</p><p translation-origin="off">The user should be able to get to these details in three ways.</p><ol><li><p translation-result="on">通过在仪表盘中点击某个英雄。</p><p translation-origin="off">By clicking a hero in the dashboard.</p></li><li><p translation-result="on">通过在英雄列表中点击某个英雄。</p><p translation-origin="off">By clicking a hero in the heroes list.</p></li><li><p translation-result="on">通过把一个“深链接” URL 粘贴到浏览器的地址栏中来指定要显示的英雄。</p><p translation-origin="off">By pasting a "deep link" URL into the browser address bar that identifies the hero to display.</p></li></ol><p translation-result="on">在这一节，你将能导航到 <code>HeroDetailComponent</code>，并把它从 <code>HeroesComponent</code> 中解放出来。</p><p translation-origin="off">In this section, you'll enable navigation to the <code>HeroDetailsComponent</code> and liberate it from the <code>HeroesComponent</code>.</p><h3 id="delete-hero-details-from-heroescomponent" translation-result="on">从 <code>HeroesComponent</code> 中删除<em>英雄详情</em><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#delete-hero-details-from-heroescomponent"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="delete-hero-details-from-heroescomponent">Delete <em>hero details</em> from <code>HeroesComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#delete-hero-details-from-heroescomponent"><i class="material-icons">link</i></a></h3><p translation-result="on">当用户在 <code>HeroesComponent</code> 中点击某个英雄条目时，应用应该能导航到 <code>HeroDetailComponent</code>，从英雄列表视图切换到英雄详情视图。 英雄列表视图将不再显示，而英雄详情视图要显示出来。</p><p translation-origin="off">When the user clicks a hero item in the <code>HeroesComponent</code>, the app should navigate to the <code>HeroDetailComponent</code>, replacing the heroes list view with the hero detail view. The heroes list view should no longer show hero details as it does now.</p><p translation-result="on">打开 <code>HeroesComponent</code> 的模板文件（<code>heroes/heroes.component.html</code>），并从底部删除 <code>&lt;app-hero-detail&gt;</code> 元素。</p><p translation-origin="off">Open the <code>HeroesComponent</code> template (<code>heroes/heroes.component.html</code>) and delete the <code>&lt;app-hero-detail&gt;</code> element from the bottom.</p><p translation-result="on">目前，点击某个英雄条目还没有反应。不过当你启用了到 <code>HeroDetailComponent</code> 的路由之后，<a href="tutorial/toh-pt5#heroes-component-links">很快就能修复它</a>。</p><p translation-origin="off">Clicking a hero item now does nothing. You'll <a href="tutorial/toh-pt5#heroes-component-links">fix that shortly</a> after you enable routing to the <code>HeroDetailComponent</code>.</p><h3 id="add-a-hero-detail-route" translation-result="on">添加<em>英雄详情</em>视图<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-hero-detail-route"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="add-a-hero-detail-route">Add a <em>hero detail</em> route<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-a-hero-detail-route"><i class="material-icons">link</i></a></h3><p translation-result="on">要导航到 <code>id</code> 为 <code>11</code> 的英雄的<em>详情</em>视图，类似于 <code>~/detail/11</code> 的 URL 将是一个不错的 URL。</p><p translation-origin="off">A URL like <code>~/detail/11</code> would be a good URL for navigating to the <em>Hero Detail</em> view of the hero whose <code>id</code> is <code>11</code>.</p><p translation-result="on">打开 <code>AppRoutingModule</code> 并导入 <code>HeroDetailComponent</code>。</p><p translation-origin="off">Open <code>AppRoutingModule</code> and import <code>HeroDetailComponent</code>.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" region="import-herodetail" header="src/app/app-routing.module.ts (import HeroDetailComponent)" ng-version="9.0.0-rc.11"><div style="display:none">import { HeroDetailComponent } from './hero-detail/hero-detail.component';</div><header class="ng-star-inserted">src/app/app-routing.module.ts (import HeroDetailComponent)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (import HeroDetailComponent)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">HeroDetailComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">  </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./hero-detail/hero-detail.component'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><p translation-result="on">然后把一个<em>参数化</em>路由添加到 <code>AppRoutingModule.routes</code> 数组中，它要匹配指向<em>英雄详情</em>视图的路径。</p><p translation-origin="off">Then add a <em>parameterized</em> route to the <code>AppRoutingModule.routes</code> array that matches the path pattern to the <em>hero detail</em> view.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" header="src/app/app-routing.module.ts" region="detail-route" ng-version="9.0.0-rc.11"><div style="display:none">{ path: 'detail/:id', component: HeroDetailComponent },</div><header class="ng-star-inserted">src/app/app-routing.module.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'detail/:id'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroDetailComponent</span><span class="pln"> </span><span class="pun">},</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>path</code> 中的冒号（<code>:</code>）表示 <code>:id</code> 是一个占位符，它表示某个特定英雄的 <code>id</code>。</p><p translation-origin="off">The colon (:) in the <code>path</code> indicates that <code>:id</code> is a placeholder for a specific hero <code>id</code>.</p><p translation-result="on">此刻，应用中的所有路由都就绪了。</p><p translation-origin="off">At this point, all application routes are in place.</p><code-example path="toh-pt5/src/app/app-routing.module.ts" region="routes" header="src/app/app-routing.module.ts (all routes)" ng-version="9.0.0-rc.11"><div style="display:none">const routes: <a href="api/router/Routes" class="code-anchor">Routes</a> = [ { path: '', <a href="api/router/Route#redirectTo" class="code-anchor">redirectTo</a>: '/dashboard', <a href="api/router/Route#pathMatch" class="code-anchor">pathMatch</a>: '<a href="api/core/Version#full" class="code-anchor">full</a>' }, { path: 'dashboard', component: DashboardComponent }, { path: 'detail/:id', component: HeroDetailComponent }, { path: 'heroes', component: HeroesComponent } ];</div><header class="ng-star-inserted">src/app/app-routing.module.ts (all routes)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts (all routes)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">const</span><span class="pln"> routes</span><span class="pun">:</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#redirectTo" class="code-anchor"><span class="pln">redirectTo</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'/dashboard'</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#pathMatch" class="code-anchor"><span class="pln">pathMatch</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'</span><a href="api/core/Version#full" class="code-anchor"><span class="str">full</span></a><span class="str">'</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">DashboardComponent</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'detail/:id'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroDetailComponent</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'heroes'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">
</span><span class="pun">];</span></code>
    </pre></aio-code></code-example><h3 id="dashboardcomponent-hero-links" translation-result="on"><code>DashboardComponent</code> 中的英雄链接<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#dashboardcomponent-hero-links"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="dashboardcomponent-hero-links"><code>DashboardComponent</code> hero links<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#dashboardcomponent-hero-links"><i class="material-icons">link</i></a></h3><p translation-result="on">此刻，<code>DashboardComponent</code> 中的英雄连接还没有反应。</p><p translation-origin="off">The <code>DashboardComponent</code> hero links do nothing at the moment.</p><p translation-result="on">路由器已经有一个指向 <code>HeroDetailComponent</code> 的路由了， 修改仪表盘中的英雄连接，让它们通过参数化的英雄详情路由进行导航。</p><p translation-origin="off">Now that the router has a route to <code>HeroDetailComponent</code>, fix the dashboard hero links to navigate via the <em>parameterized</em> dashboard route.</p><code-example path="toh-pt5/src/app/dashboard/dashboard.component.html" region="click" header="src/app/dashboard/dashboard.component.html (hero links)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;a *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes" class="col-1-4" <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/detail/{{hero.id}}"&gt; &lt;div class="module hero"&gt; &lt;h4&gt;{{hero.name}}&lt;/h4&gt; &lt;/div&gt; &lt;/a&gt;</div><header class="ng-star-inserted">src/app/dashboard/dashboard.component.html (hero links)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/dashboard/dashboard.component.html (hero links)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;a</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"col-1-4"</span><span class="pln">
    </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/detail/{{hero.id}}"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"module hero"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;h4&gt;</span><span class="pln">{{hero.name}}</span><span class="tag">&lt;/h4&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/a&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">你正在 <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> 复写器中使用 Angular 的<a href="guide/template-syntax#interpolation">插值绑定</a>来把当前迭代的 <code>hero.id</code> 插入到每个 <a href="tutorial/toh-pt5#routerlink"><code>routerLink</code></a>中。</p><p translation-origin="off">You're using Angular <a href="guide/template-syntax#interpolation">interpolation binding</a> within the <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code> repeater to insert the current iteration's <code>hero.id</code> into each <a href="tutorial/toh-pt5#routerlink"><code>routerLink</code></a>.</p><a id="heroes-component-links"></a><h3 id="heroescomponent-hero-links" translation-result="on"><code>HeroesComponent</code> 中的英雄链接<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#heroescomponent-hero-links"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="heroescomponent-hero-links"><code>HeroesComponent</code> hero links<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#heroescomponent-hero-links"><i class="material-icons">link</i></a></h3><p translation-result="on"><code>HeroesComponent</code> 中的这些英雄条目都是 <code>&lt;li&gt;</code> 元素，它们的点击事件都绑定到了组件的 <code>onSelect()</code> 方法中。</p><p translation-origin="off">The hero items in the <code>HeroesComponent</code> are <code>&lt;li&gt;</code> elements whose click events are bound to the component's <code>onSelect()</code> method.</p><code-example path="toh-pt4/src/app/heroes/heroes.component.html" region="list" header="src/app/heroes/heroes.component.html (list with onSelect)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;ul class="heroes"&gt; &lt;li *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes" [class.selected]="hero === selectedHero" (click)="onSelect(hero)"&gt; &lt;span class="badge"&gt;{{hero.id}}&lt;/span&gt; {{hero.name}} &lt;/li&gt; &lt;/ul&gt;</div><header class="ng-star-inserted">src/app/heroes/heroes.component.html (list with onSelect)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/heroes/heroes.component.html (list with onSelect)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;ul</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"heroes"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;li</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="pln">
    [</span><span class="atn">class</span><span class="pln">.</span><span class="atn">selected</span><span class="pln">]</span><span class="pun">=</span><span class="atv">"hero === selectedHero"</span><span class="pln">
    (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"onSelect(hero)"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"badge"</span><span class="tag">&gt;</span><span class="pln">{{hero.id}}</span><span class="tag">&lt;/span&gt;</span><span class="pln"> {{hero.name}}
  </span><span class="tag">&lt;/li&gt;</span><span class="pln">
</span><span class="tag">&lt;/ul&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">清理 <code>&lt;li&gt;</code>，只保留它的 <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code>，把徽章（<code>&lt;badge&gt;</code>）和名字包裹进一个 <code>&lt;a&gt;</code> 元素中， 并且像仪表盘的模板中那样为这个 <code>&lt;a&gt;</code> 元素添加一个 <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> 属性。</p><p translation-origin="off">Strip the <code>&lt;li&gt;</code> back to just its <code>*<a href="api/common/NgForOf" class="code-anchor">ngFor</a></code>, wrap the badge and name in an anchor element (<code>&lt;a&gt;</code>), and add a <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> attribute to the anchor that is the same as in the dashboard template</p><code-example path="toh-pt5/src/app/heroes/heroes.component.html" region="list" header="src/app/heroes/heroes.component.html (list with links)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;ul class="heroes"&gt; &lt;li *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes"&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/detail/{{hero.id}}"&gt; &lt;span class="badge"&gt;{{hero.id}}&lt;/span&gt; {{hero.name}} &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;</div><header class="ng-star-inserted">src/app/heroes/heroes.component.html (list with links)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/heroes/heroes.component.html (list with links)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;ul</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"heroes"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;li</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/detail/{{hero.id}}"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"badge"</span><span class="tag">&gt;</span><span class="pln">{{hero.id}}</span><span class="tag">&lt;/span&gt;</span><span class="pln"> {{hero.name}}
    </span><span class="tag">&lt;/a&gt;</span><span class="pln">
  </span><span class="tag">&lt;/li&gt;</span><span class="pln">
</span><span class="tag">&lt;/ul&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">你还要修改私有样式表（<code>heroes.component.css</code>），让列表恢复到以前的外观。 修改后的样式表参见本指南底部的<a href="tutorial/toh-pt5#heroescomponent">最终代码</a>。</p><p translation-origin="off">You'll have to fix the private stylesheet (<code>heroes.component.css</code>) to make the list look as it did before. Revised styles are in the <a href="tutorial/toh-pt5#heroescomponent">final code review</a> at the bottom of this guide.</p><h4 id="remove-dead-code-optional" translation-result="on">移除死代码（可选）<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#remove-dead-code-optional"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="remove-dead-code-optional">Remove dead code (optional)<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#remove-dead-code-optional"><i class="material-icons">link</i></a></h4><p translation-result="on">虽然 <code>HeroesComponent</code> 类仍然能正常工作，但 <code>onSelect()</code> 方法和 <code>selectedHero</code> 属性已经没用了。</p><p translation-origin="off">While the <code>HeroesComponent</code> class still works, the <code>onSelect()</code> method and <code>selectedHero</code> property are no longer used.</p><p translation-result="on">最好清理掉它们，将来你会体会到这么做的好处。 下面是删除了死代码之后的类。</p><p translation-origin="off">It's nice to tidy up and you'll be grateful to yourself later. Here's the class after pruning away the dead code.</p><code-example path="toh-pt5/src/app/heroes/heroes.component.ts" region="class" header="src/app/heroes/heroes.component.ts (cleaned up)" ng-version="9.0.0-rc.11"><div style="display:none">export class HeroesComponent implements <a href="api/core/OnInit" class="code-anchor">OnInit</a> { heroes: Hero[]; constructor(private heroService: HeroService) { } ngOnInit() { this.getHeroes(); } getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes =&gt; this.heroes = heroes); } }</div><header class="ng-star-inserted">src/app/heroes/heroes.component.ts (cleaned up)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/heroes/heroes.component.ts (cleaned up)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="kwd">implements</span><span class="pln"> </span><a href="api/core/OnInit" class="code-anchor"><span class="typ">OnInit</span></a><span class="pln"> </span><span class="pun">{</span><span class="pln">
  heroes</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Hero</span><span class="pun">[];</span><span class="pln">

  </span><span class="kwd">constructor</span><span class="pun">(</span><span class="kwd">private</span><span class="pln"> heroService</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroService</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">}</span><span class="pln">

  ngOnInit</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">getHeroes</span><span class="pun">();</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">

  getHeroes</span><span class="pun">():</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">heroService</span><span class="pun">.</span><span class="pln">getHeroes</span><span class="pun">()</span><span class="pln">
    </span><span class="pun">.</span><span class="pln">subscribe</span><span class="pun">(</span><span class="pln">heroes </span><span class="pun">=&gt;</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">heroes </span><span class="pun">=</span><span class="pln"> heroes</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><h2 id="routable-herodetailcomponent" translation-result="on">支持路由的 <code>HeroDetailComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#routable-herodetailcomponent"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="routable-herodetailcomponent">Routable <code>HeroDetailComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#routable-herodetailcomponent"><i class="material-icons">link</i></a></h2><p translation-result="on">以前，父组件 <code>HeroesComponent</code> 会设置 <code>HeroDetailComponent.hero</code> 属性，然后 <code>HeroDetailComponent</code> 就会显示这个英雄。</p><p translation-origin="off">Previously, the parent <code>HeroesComponent</code> set the <code>HeroDetailComponent.hero</code> property and the <code>HeroDetailComponent</code> displayed the hero.</p><p translation-result="on"><code>HeroesComponent</code> 已经不会再那么做了。 现在，当路由器会在响应形如 <code>~/detail/11</code> 的 URL 时创建 <code>HeroDetailComponent</code>。</p><p translation-origin="off"><code>HeroesComponent</code> doesn't do that anymore. Now the router creates the <code>HeroDetailComponent</code> in response to a URL such as <code>~/detail/11</code>.</p><p translation-result="on"><code>HeroDetailComponent</code> 需要从一种新的途径获取<em>要显示的英雄</em>。 本节会讲解如下操作：</p><p translation-origin="off">The <code>HeroDetailComponent</code> needs a new way to obtain the hero-to-display. This section explains the following:</p><ul><li><p translation-result="on">获取创建本组件的路由</p><p translation-origin="off">Get the route that created it</p></li><li><p translation-result="on">从这个路由中提取出 <code>id</code></p><p translation-origin="off">Extract the <code>id</code> from the route</p></li><li><p translation-result="on">通过 <code>HeroService</code> 从服务器上获取具有这个 <code>id</code> 的英雄数据。</p><p translation-origin="off">Acquire the hero with that <code>id</code> from the server via the <code>HeroService</code></p></li></ul><p translation-result="on">先添加下列导入语句：</p><p translation-origin="off">Add the following imports:</p><code-example path="toh-pt5/src/app/hero-detail/hero-detail.component.ts" region="added-imports" header="src/app/hero-detail/hero-detail.component.ts" ng-version="9.0.0-rc.11"><div style="display:none">import { <a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a> } from '@angular/router'; import { <a href="api/common/Location" class="code-anchor">Location</a> } from '@angular/common'; import { HeroService } from '../hero.service';</div><header class="ng-star-inserted">src/app/hero-detail/hero-detail.component.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/router/ActivatedRoute" class="code-anchor"><span class="typ">ActivatedRoute</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/router'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/common/Location" class="code-anchor"><span class="typ">Location</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/common'</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">HeroService</span><span class="pln"> </span><span class="pun">}</span><span class="pln">  </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'../hero.service'</span><span class="pun">;</span></code>
    </pre></aio-code></code-example><a id="hero-detail-ctor"></a><p translation-result="on">然后把 <code><a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a></code>、<code>HeroService</code> 和 <code><a href="api/common/Location" class="code-anchor">Location</a></code> 服务注入到构造函数中，将它们的值保存到私有变量里：</p><p translation-origin="off">Inject the <code><a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a></code>, <code>HeroService</code>, and <code><a href="api/common/Location" class="code-anchor">Location</a></code> services into the constructor, saving their values in private fields:</p><code-example path="toh-pt5/src/app/hero-detail/hero-detail.component.ts" header="src/app/hero-detail/hero-detail.component.ts" region="ctor" ng-version="9.0.0-rc.11"><div style="display:none">constructor( private route: <a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a>, private heroService: HeroService, private location: <a href="api/common/Location" class="code-anchor">Location</a> ) {}</div><header class="ng-star-inserted">src/app/hero-detail/hero-detail.component.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">constructor</span><span class="pun">(</span><span class="pln">
  </span><span class="kwd">private</span><span class="pln"> route</span><span class="pun">:</span><span class="pln"> </span><a href="api/router/ActivatedRoute" class="code-anchor"><span class="typ">ActivatedRoute</span></a><span class="pun">,</span><span class="pln">
  </span><span class="kwd">private</span><span class="pln"> heroService</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroService</span><span class="pun">,</span><span class="pln">
  </span><span class="kwd">private</span><span class="pln"> location</span><span class="pun">:</span><span class="pln"> </span><a href="api/common/Location" class="code-anchor"><span class="typ">Location</span></a><span class="pln">
</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{}</span></code>
    </pre></aio-code></code-example><p translation-result="on"><a href="api/router/ActivatedRoute"><code>ActivatedRoute</code></a>保存着到这个 <code>HeroDetailComponent</code> 实例的路由信息。 这个组件对从 URL 中提取的路由参数感兴趣。 其中的 <code>id</code> 参数就是要显示的英雄的 <code>id</code>。</p><p translation-origin="off">The <a href="api/router/ActivatedRoute"><code>ActivatedRoute</code></a>holds information about the route to this instance of the <code>HeroDetailComponent</code>. This component is interested in the route's parameters extracted from the URL. The "id" parameter is the <code>id</code> of the hero to display.</p><p translation-result="on"><a href="tutorial/toh-pt4"><code>HeroService</code></a>从远端服务器获取英雄数据，本组件将使用它来获取要显示的英雄。</p><p translation-origin="off">The <a href="tutorial/toh-pt4"><code>HeroService</code></a>gets hero data from the remote server and this component will use it to get the hero-to-display.</p><p translation-result="on"><a href="api/common/Location"><code>location</code></a>是一个 Angular 的服务，用来与浏览器打交道。 <a href="tutorial/toh-pt5#goback">稍后</a>，你就会使用它来导航回上一个视图。</p><p translation-origin="off">The <a href="api/common/Location"><code>location</code></a>is an Angular service for interacting with the browser. You'll use it <a href="tutorial/toh-pt5#goback">later</a> to navigate back to the view that navigated here.</p><h3 id="extract-the-id-route-parameter" translation-result="on">从路由参数中提取 <code>id</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#extract-the-id-route-parameter"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="extract-the-id-route-parameter">Extract the <code>id</code> route parameter<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#extract-the-id-route-parameter"><i class="material-icons">link</i></a></h3><p translation-result="on">在 <code>ngOnInit()</code> <a href="guide/lifecycle-hooks#oninit">生命周期钩子</a> 中调用 <code>getHero()</code>，代码如下：</p><p translation-origin="off">In the <code>ngOnInit()</code> <a href="guide/lifecycle-hooks#oninit">lifecycle hook</a> call <code>getHero()</code> and define it as follows.</p><code-example path="toh-pt5/src/app/hero-detail/hero-detail.component.ts" header="src/app/hero-detail/hero-detail.component.ts" region="ngOnInit" ng-version="9.0.0-rc.11"><div style="display:none">ngOnInit(): void { this.getHero(); } getHero(): void { const id = +this.route.snapshot.paramMap.get('id'); this.heroService.getHero(id) .subscribe(hero =&gt; this.hero = hero); }</div><header class="ng-star-inserted">src/app/hero-detail/hero-detail.component.ts</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">ngOnInit</span><span class="pun">():</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">getHero</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

getHero</span><span class="pun">():</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">const</span><span class="pln"> id </span><span class="pun">=</span><span class="pln"> </span><span class="pun">+</span><span class="kwd">this</span><span class="pun">.</span><span class="pln">route</span><span class="pun">.</span><span class="pln">snapshot</span><span class="pun">.</span><span class="pln">paramMap</span><span class="pun">.</span><span class="kwd">get</span><span class="pun">(</span><span class="str">'id'</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">heroService</span><span class="pun">.</span><span class="pln">getHero</span><span class="pun">(</span><span class="pln">id</span><span class="pun">)</span><span class="pln">
    </span><span class="pun">.</span><span class="pln">subscribe</span><span class="pun">(</span><span class="pln">hero </span><span class="pun">=&gt;</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">hero </span><span class="pun">=</span><span class="pln"> hero</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on"><code>route.snapshot</code> 是一个路由信息的静态快照，抓取自组件刚刚创建完毕之后。</p><p translation-origin="off">The <code>route.snapshot</code> is a static image of the route information shortly after the component was created.</p><p translation-result="on"><code>paramMap</code> 是一个从 URL 中提取的路由参数值的字典。 <code>"id"</code> 对应的值就是要获取的英雄的 <code>id</code>。</p><p translation-origin="off">The <code>paramMap</code> is a dictionary of route parameter values extracted from the URL. The <code>"id"</code> key returns the <code>id</code> of the hero to fetch.</p><p translation-result="on">路由参数总会是字符串。 JavaScript 的 (+) 操作符会把字符串转换成数字，英雄的 <code>id</code> 就是数字类型。</p><p translation-origin="off">Route parameters are always strings. The JavaScript (+) operator converts the string to a number, which is what a hero <code>id</code> should be.</p><p translation-result="on">刷新浏览器，应用挂了。出现一个编译错误，因为 <code>HeroService</code> 没有一个名叫 <code>getHero()</code> 的方法。 这就添加它。</p><p translation-origin="off">The browser refreshes and the app crashes with a compiler error. <code>HeroService</code> doesn't have a <code>getHero()</code> method. Add it now.</p><h3 id="add-heroservicegethero" translation-result="on">添加 <code>HeroService.getHero()</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-heroservicegethero"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="add-heroservicegethero">Add <code>HeroService.getHero()</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#add-heroservicegethero"><i class="material-icons">link</i></a></h3><p translation-result="on">添加 <code>HeroService</code>，并在 <code>getHeroes()</code> 后面添加如下的 <code>getHero()</code> 方法，它接收 <code>id</code> 参数：</p><p translation-origin="off">Open <code>HeroService</code> and add the following <code>getHero()</code> method with the <code>id</code> after the <code>getHeroes()</code> method:</p><code-example path="toh-pt5/src/app/hero.service.ts" region="getHero" header="src/app/hero.service.ts (getHero)" ng-version="9.0.0-rc.11"><div style="display:none">getHero(id: number): Observable&lt;Hero&gt; { // TODO: send the <a href="api/common/http/HttpErrorResponse#message" class="code-anchor">message</a> _after_ fetching the hero this.messageService.add(`HeroService: fetched hero id=${id}`); return of(HEROES.find(hero =&gt; hero.id === id)); }</div><header class="ng-star-inserted">src/app/hero.service.ts (getHero)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero.service.ts (getHero)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">getHero</span><span class="pun">(</span><span class="pln">id</span><span class="pun">:</span><span class="pln"> number</span><span class="pun">):</span><span class="pln"> </span><span class="typ">Observable</span><span class="pun">&lt;</span><span class="typ">Hero</span><span class="pun">&gt;</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="com">// TODO: send the </span><a href="api/common/http/HttpErrorResponse#message" class="code-anchor"><span class="com">message</span></a><span class="com"> _after_ fetching the hero</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">messageService</span><span class="pun">.</span><span class="kwd">add</span><span class="pun">(</span><span class="str">`HeroService: fetched hero id=${id}`</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">return</span><span class="pln"> of</span><span class="pun">(</span><span class="pln">HEROES</span><span class="pun">.</span><span class="pln">find</span><span class="pun">(</span><span class="pln">hero </span><span class="pun">=&gt;</span><span class="pln"> hero</span><span class="pun">.</span><span class="pln">id </span><span class="pun">===</span><span class="pln"> id</span><span class="pun">));</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><div class="alert is-important"><p translation-result="on">注意，反引号 ( ` ) 用于定义 JavaScript 的 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">模板字符串字面量</a>，以便嵌入 <code>id</code>。</p><p translation-origin="off">Note the backticks ( ` ) that define a JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"><em>template literal</em></a> for embedding the <code>id</code>.</p></div><p translation-result="on">像 <a href="tutorial/toh-pt4#observable-heroservice"><code>getHeroes()</code></a>一样，<code>getHero()</code> 也有一个异步函数签名。 它用 RxJS 的 <code>of()</code> 函数返回一个 <code>Observable</code> 形式的<em>模拟英雄数据</em>。</p><p translation-origin="off">Like <a href="tutorial/toh-pt4#observable-heroservice"><code>getHeroes()</code></a>, <code>getHero()</code> has an asynchronous signature. It returns a <em>mock hero</em> as an <code>Observable</code>, using the RxJS <code>of()</code> function.</p><p translation-result="on">你将来可以用一个真实的 <code>Http</code> 请求来重新实现 <code>getHero()</code>，而不用修改调用了它的 <code>HeroDetailComponent</code>。</p><p translation-origin="off">You'll be able to re-implement <code>getHero()</code> as a real <code>Http</code> request without having to change the <code>HeroDetailComponent</code> that calls it.</p><h4 id="try-it-1" translation-result="on">试试看<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#try-it-1"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="try-it-1">Try it<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#try-it-1"><i class="material-icons">link</i></a></h4><p translation-result="on">刷新浏览器，应用又恢复正常了。 你可以在仪表盘或英雄列表中点击一个英雄来导航到该英雄的详情视图。</p><p translation-origin="off">The browser refreshes and the app is working again. You can click a hero in the dashboard or in the heroes list and navigate to that hero's detail view.</p><p translation-result="on">如果你在浏览器的地址栏中粘贴了 <code>localhost:4200/detail/11</code>，路由器也会导航到 <code>id: 11</code> 的英雄（"Dr. Nice"）的详情视图。</p><p translation-origin="off">If you paste <code>localhost:4200/detail/11</code> in the browser address bar, the router navigates to the detail view for the hero with <code>id: 11</code>, "Dr Nice".</p><a id="goback"></a><h3 id="find-the-way-back" translation-result="on">回到原路<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#find-the-way-back"><i class="material-icons">link</i></a></h3><h3 translation-origin="off" id="find-the-way-back">Find the way back<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#find-the-way-back"><i class="material-icons">link</i></a></h3><p translation-result="on">通过点击浏览器的后退按钮，你可以回到英雄列表或仪表盘视图，这取决于你从哪里进入的详情视图。</p><p translation-origin="off">By clicking the browser's back button, you can go back to the hero list or dashboard view, depending upon which sent you to the detail view.</p><p translation-result="on">如果能在 <code>HeroDetail</code> 视图中也有这么一个按钮就更好了。</p><p translation-origin="off">It would be nice to have a button on the <code>HeroDetail</code> view that can do that.</p><p translation-result="on">把一个<em>后退</em>按钮添加到组件模板的底部，并且把它绑定到组件的 <code>goBack()</code> 方法。</p><p translation-origin="off">Add a <em>go back</em> button to the bottom of the component template and bind it to the component's <code>goBack()</code> method.</p><code-example path="toh-pt5/src/app/hero-detail/hero-detail.component.html" region="back-button" header="src/app/hero-detail/hero-detail.component.html (back button)" ng-version="9.0.0-rc.11"><div style="display:none">&lt;button (click)="goBack()"&gt;go back&lt;/button&gt;</div><header class="ng-star-inserted">src/app/hero-detail/hero-detail.component.html (back button)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.html (back button)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;button</span><span class="pln"> (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"goBack()"</span><span class="tag">&gt;</span><span class="pln">go back</span><span class="tag">&lt;/button&gt;</span></code>
    </pre></aio-code></code-example><p translation-result="on">在组件类中添加一个 <code>goBack()</code> 方法，利用<a href="tutorial/toh-pt5#hero-detail-ctor">你以前注入的</a> <code><a href="api/common/Location" class="code-anchor">Location</a></code> 服务在浏览器的历史栈中后退一步。</p><p translation-origin="off">Add a <code>goBack()</code> <em>method</em> to the component class that navigates backward one step in the browser's history stack using the <code><a href="api/common/Location" class="code-anchor">Location</a></code> service that you <a href="tutorial/toh-pt5#hero-detail-ctor">injected previously</a>.</p><code-example path="toh-pt5/src/app/hero-detail/hero-detail.component.ts" region="goBack" header="src/app/hero-detail/hero-detail.component.ts (goBack)" ng-version="9.0.0-rc.11"><div style="display:none">goBack(): void { this.location.back(); }</div><header class="ng-star-inserted">src/app/hero-detail/hero-detail.component.ts (goBack)</header><aio-code class="headed-code"><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.ts (goBack)">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="pln">goBack</span><span class="pun">():</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">location</span><span class="pun">.</span><span class="pln">back</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span></code>
    </pre></aio-code></code-example><p translation-result="on">刷新浏览器，并开始点击。 用户能在应用中导航：从仪表盘到英雄详情再回来，从英雄列表到 mini 版英雄详情到英雄详情，再回到英雄列表。</p><p translation-origin="off">Refresh the browser and start clicking. Users can navigate around the app, from the dashboard to hero details and back, from heroes list to the mini detail to the hero details and back to the heroes again.</p><h2 id="final-code-review" translation-result="on">查看最终代码<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#final-code-review"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="final-code-review">Final code review<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#final-code-review"><i class="material-icons">link</i></a></h2><p translation-result="on">你的应用应该变成了这样<live-example ng-version="9.0.0-rc.11"><span style="display:none"></span><span><span class="ng-star-inserted"><a target="_blank" title="现场演练" href="generated/live-examples/toh-pt5/stackblitz.html">现场演练</a><span class="ng-star-inserted"> / <a download="" title="下载范例" href="generated/zips/toh-pt5/toh-pt5.zip">下载范例</a></span></span></span></live-example>。本页所提及的代码文件如下：</p><p translation-origin="off">Here are the code files discussed on this page and your app should look like this<live-example ng-version="9.0.0-rc.11"><span style="display:none"></span><span><span class="ng-star-inserted"><a target="_blank" title="现场演练" href="generated/live-examples/toh-pt5/stackblitz.html">现场演练</a><span class="ng-star-inserted"> / <a download="" title="下载范例" href="generated/zips/toh-pt5/toh-pt5.zip">下载范例</a></span></span></span></live-example>.</p><a id="approutingmodule"></a> <a id="appmodule"></a><h4 id="approutingmodule-appmodule-and-heroservice" translation-result="on"><code>AppRoutingModule</code>、<code>AppModule</code> 和 <code>HeroService</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#approutingmodule-appmodule-and-heroservice"><i class="material-icons">link</i></a></h4><h4 translation-origin="off" id="approutingmodule-appmodule-and-heroservice"><code>AppRoutingModule</code>, <code>AppModule</code>, and <code>HeroService</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#approutingmodule-appmodule-and-heroservice"><i class="material-icons">link</i></a></h4><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/app-routing.module.ts" path="toh-pt5/src/app/app-routing.module.ts">import { <a href="api/core/NgModule" class="code-anchor">NgModule</a> } from '@angular/core'; import { <a href="api/router/RouterModule" class="code-anchor">RouterModule</a>, <a href="api/router/Routes" class="code-anchor">Routes</a> } from '@angular/router'; import { DashboardComponent } from './dashboard/dashboard.component'; import { HeroesComponent } from './heroes/heroes.component'; import { HeroDetailComponent } from './hero-detail/hero-detail.component'; const routes: <a href="api/router/Routes" class="code-anchor">Routes</a> = [ { path: '', <a href="api/router/Route#redirectTo" class="code-anchor">redirectTo</a>: '/dashboard', <a href="api/router/Route#pathMatch" class="code-anchor">pathMatch</a>: '<a href="api/core/Version#full" class="code-anchor">full</a>' }, { path: 'dashboard', component: DashboardComponent }, { path: 'detail/:id', component: HeroDetailComponent }, { path: 'heroes', component: HeroesComponent } ]; @<a href="api/core/NgModule" class="code-anchor">NgModule</a>({ imports: [ RouterModule.forRoot(routes) ], exports: [ <a href="api/router/RouterModule" class="code-anchor">RouterModule</a> ] }) export class AppRoutingModule {}</code-pane><code-pane header="src/app/app.module.ts" path="toh-pt5/src/app/app.module.ts">import { <a href="api/core/NgModule" class="code-anchor">NgModule</a> } from '@angular/core'; import { <a href="api/platform-browser/BrowserModule" class="code-anchor">BrowserModule</a> } from '@angular/platform-browser'; import { <a href="api/forms/FormsModule" class="code-anchor">FormsModule</a> } from '@angular/forms'; import { AppComponent } from './app.component'; import { DashboardComponent } from './dashboard/dashboard.component'; import { HeroDetailComponent } from './hero-detail/hero-detail.component'; import { HeroesComponent } from './heroes/heroes.component'; import { MessagesComponent } from './<a href="api/service-worker/SwPush#messages" class="code-anchor">messages</a>/messages.component'; import { AppRoutingModule } from './app-routing.module'; @<a href="api/core/NgModule" class="code-anchor">NgModule</a>({ imports: [ <a href="api/platform-browser/BrowserModule" class="code-anchor">BrowserModule</a>, <a href="api/forms/FormsModule" class="code-anchor">FormsModule</a>, AppRoutingModule ], declarations: [ AppComponent, DashboardComponent, HeroesComponent, HeroDetailComponent, MessagesComponent ], bootstrap: [ AppComponent ] }) export class AppModule { }</code-pane><code-pane header="src/app/hero.service.ts" path="toh-pt5/src/app/hero.service.ts">import { <a href="api/core/Injectable" class="code-anchor">Injectable</a> } from '@angular/core'; import { Observable, of } from 'rxjs'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; import { MessageService } from './message.service'; @<a href="api/core/Injectable" class="code-anchor">Injectable</a>({ <a href="api/core/Injectable#providedIn" class="code-anchor">providedIn</a>: 'root' }) export class HeroService { constructor(private messageService: MessageService) { } getHeroes(): Observable&lt;Hero[]&gt; { // TODO: send the <a href="api/common/http/HttpErrorResponse#message" class="code-anchor">message</a> _after_ fetching the heroes this.messageService.add('HeroService: fetched heroes'); return of(HEROES); } getHero(id: number): Observable&lt;Hero&gt; { // TODO: send the <a href="api/common/http/HttpErrorResponse#message" class="code-anchor">message</a> _after_ fetching the hero this.messageService.add(`HeroService: fetched hero id=${id}`); return of(HEROES.find(hero =&gt; hero.id === id)); } }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-1-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-1-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/app-routing.module.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-1-1" tabindex="-1" aria-posinset="2" aria-setsize="3" aria-controls="mat-tab-content-1-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/app.module.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-1-2" tabindex="-1" aria-posinset="3" aria-setsize="3" aria-controls="mat-tab-content-1-2" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/hero.service.ts</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:233px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-5 mat-tab-body-active ng-star-inserted" id="mat-tab-content-1-0" aria-labelledby="mat-tab-label-1-0"><div class="mat-tab-body-content ng-tns-c50-5 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app-routing.module.ts">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/core/NgModule" class="code-anchor"><span class="typ">NgModule</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln">             </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/core'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><a href="api/router/RouterModule" class="code-anchor"><span class="typ">RouterModule</span></a><span class="pun">,</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'@angular/router'</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">DashboardComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">   </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./dashboard/dashboard.component'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">      </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./heroes/heroes.component'</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">HeroDetailComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">  </span><span class="kwd">from</span><span class="pln"> </span><span class="str">'./hero-detail/hero-detail.component'</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> routes</span><span class="pun">:</span><span class="pln"> </span><a href="api/router/Routes" class="code-anchor"><span class="typ">Routes</span></a><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#redirectTo" class="code-anchor"><span class="pln">redirectTo</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'/dashboard'</span><span class="pun">,</span><span class="pln"> </span><a href="api/router/Route#pathMatch" class="code-anchor"><span class="pln">pathMatch</span></a><span class="pun">:</span><span class="pln"> </span><span class="str">'</span><a href="api/core/Version#full" class="code-anchor"><span class="str">full</span></a><span class="str">'</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'dashboard'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">DashboardComponent</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'detail/:id'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroDetailComponent</span><span class="pln"> </span><span class="pun">},</span><span class="pln">
  </span><span class="pun">{</span><span class="pln"> path</span><span class="pun">:</span><span class="pln"> </span><span class="str">'heroes'</span><span class="pun">,</span><span class="pln"> component</span><span class="pun">:</span><span class="pln"> </span><span class="typ">HeroesComponent</span><span class="pln"> </span><span class="pun">}</span><span class="pln">
</span><span class="pun">];</span><span class="pln">

</span><span class="lit">@</span><a href="api/core/NgModule" class="code-anchor"><span class="lit">NgModule</span></a><span class="pun">({</span><span class="pln">
  imports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><span class="typ">RouterModule</span><span class="pun">.</span><span class="pln">forRoot</span><span class="pun">(</span><span class="pln">routes</span><span class="pun">)</span><span class="pln"> </span><span class="pun">],</span><span class="pln">
  exports</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><a href="api/router/RouterModule" class="code-anchor"><span class="typ">RouterModule</span></a><span class="pln"> </span><span class="pun">]</span><span class="pln">
</span><span class="pun">})</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">AppRoutingModule</span><span class="pln"> </span><span class="pun">{}</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-6 ng-star-inserted" id="mat-tab-content-1-1" aria-labelledby="mat-tab-label-1-1"><div class="mat-tab-body-content ng-tns-c50-6 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-7 ng-star-inserted" id="mat-tab-content-1-2" aria-labelledby="mat-tab-label-1-2"><div class="mat-tab-body-content ng-tns-c50-7 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><a id="appcomponent"></a><h4 id="appcomponent"><code>AppComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#appcomponent"><i class="material-icons">link</i></a></h4><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/app.component.html" path="toh-pt5/src/app/app.component.html">&lt;h1&gt;{{title}}&lt;/h1&gt; &lt;nav&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/dashboard"&gt;Dashboard&lt;/a&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/heroes"&gt;Heroes&lt;/a&gt; &lt;/nav&gt; &lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;&lt;/<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt; &lt;app-messages&gt;&lt;/app-messages&gt;</code-pane><code-pane header="src/app/app.component.css" path="toh-pt5/src/app/app.component.css">/* AppComponent's private CSS styles */ h1 { font-size: 1.2em; margin-bottom: 0; } h2 { font-size: 2em; margin-top: 0; padding-top: 0; } nav a { padding: 5px 10px; text-decoration: none; margin-top: 10px; display: inline-block; background-color: #eee; border-radius: 4px; } nav a:visited, a:link { color: #334953; } nav a:hover { color: #039be5; background-color: #cfd8dc; } nav a.active { color: #039be5; }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-2-0" tabindex="0" aria-posinset="1" aria-setsize="2" aria-controls="mat-tab-content-2-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/app.component.html</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-2-1" tabindex="-1" aria-posinset="2" aria-setsize="2" aria-controls="mat-tab-content-2-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/app.component.css</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:225px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-8 mat-tab-body-active ng-star-inserted" id="mat-tab-content-2-0" aria-labelledby="mat-tab-label-2-0"><div class="mat-tab-body-content ng-tns-c50-8 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/app.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h1&gt;</span><span class="pln">{{title}}</span><span class="tag">&lt;/h1&gt;</span><span class="pln">
</span><span class="tag">&lt;nav&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/dashboard"</span><span class="tag">&gt;</span><span class="pln">Dashboard</span><span class="tag">&lt;/a&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/heroes"</span><span class="tag">&gt;</span><span class="pln">Heroes</span><span class="tag">&lt;/a&gt;</span><span class="pln">
</span><span class="tag">&lt;/nav&gt;</span><span class="pln">
</span><span class="tag">&lt;</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;&lt;/</span><a href="api/router/RouterOutlet" class="code-anchor"><span class="tag">router-outlet</span></a><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;app-messages&gt;&lt;/app-messages&gt;</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-9 ng-star-inserted" id="mat-tab-content-2-1" aria-labelledby="mat-tab-label-2-1"><div class="mat-tab-body-content ng-tns-c50-9 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><a id="dashboardcomponent"></a><h4 id="dashboardcomponent"><code>DashboardComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#dashboardcomponent"><i class="material-icons">link</i></a></h4><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/dashboard/dashboard.component.html" path="toh-pt5/src/app/dashboard/dashboard.component.html">&lt;h3&gt;Top Heroes&lt;/h3&gt; &lt;div class="grid grid-pad"&gt; &lt;a *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes" class="col-1-4" <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/detail/{{hero.id}}"&gt; &lt;div class="module hero"&gt; &lt;h4&gt;{{hero.name}}&lt;/h4&gt; &lt;/div&gt; &lt;/a&gt; &lt;/div&gt;</code-pane><code-pane header="src/app/dashboard/dashboard.component.ts" path="toh-pt5/src/app/dashboard/dashboard.component.ts">import { <a href="api/core/Component" class="code-anchor">Component</a>, <a href="api/core/OnInit" class="code-anchor">OnInit</a> } from '@angular/core'; import { Hero } from '../hero'; import { HeroService } from '../hero.service'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-dashboard', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './dashboard.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: [ './dashboard.component.css' ] }) export class DashboardComponent implements <a href="api/core/OnInit" class="code-anchor">OnInit</a> { heroes: Hero[] = []; constructor(private heroService: HeroService) { } ngOnInit() { this.getHeroes(); } getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes =&gt; this.heroes = heroes.slice(1, 5)); } }</code-pane><code-pane header="src/app/dashboard/dashboard.component.css" path="toh-pt5/src/app/dashboard/dashboard.component.css">/* DashboardComponent's private CSS styles */ [class*='col-'] { float: left; padding-right: 20px; padding-bottom: 20px; } [class*='col-']:last-of-type { padding-right: 0; } a { text-decoration: none; } *, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } h3 { text-align: center; margin-bottom: 0; } h4 { <a href="api/router/Scroll#position" class="code-anchor">position</a>: relative; } .grid { margin: 0; } .col-1-4 { width: 25%; } .module { padding: 20px; text-align: center; color: #eee; max-height: 120px; min-width: 120px; background-color: #3f525c; border-radius: 2px; } .module:hover { background-color: #eee; cursor: pointer; color: #607d8b; } .grid-pad { padding: 10px 0; } .grid-pad &gt; [class*='col-']:last-of-type { padding-right: 20px; } @media (max-width: 600px) { .module { font-size: 10px; max-height: 75px; } } @media (max-width: 1024px) { .grid { margin: 0; } .module { min-width: 60px; } }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header mat-tab-header-pagination-controls-enabled"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-3-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-3-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.html</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-3-1" tabindex="-1" aria-posinset="2" aria-setsize="3" aria-controls="mat-tab-content-3-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-3-2" tabindex="-1" aria-posinset="3" aria-setsize="3" aria-controls="mat-tab-content-3-2" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/dashboard/dashboard.component.css</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:338px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-10 mat-tab-body-active ng-star-inserted" id="mat-tab-content-3-0" aria-labelledby="mat-tab-label-3-0"><div class="mat-tab-body-content ng-tns-c50-10 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/dashboard/dashboard.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h3&gt;</span><span class="pln">Top Heroes</span><span class="tag">&lt;/h3&gt;</span><span class="pln">
</span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"grid grid-pad"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;a</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"col-1-4"</span><span class="pln">
      </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/detail/{{hero.id}}"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"module hero"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;h4&gt;</span><span class="pln">{{hero.name}}</span><span class="tag">&lt;/h4&gt;</span><span class="pln">
    </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;/a&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-11 ng-star-inserted" id="mat-tab-content-3-1" aria-labelledby="mat-tab-label-3-1"><div class="mat-tab-body-content ng-tns-c50-11 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-12 ng-star-inserted" id="mat-tab-content-3-2" aria-labelledby="mat-tab-label-3-2"><div class="mat-tab-body-content ng-tns-c50-12 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><a id="heroescomponent"></a><h4 id="heroescomponent"><code>HeroesComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#heroescomponent"><i class="material-icons">link</i></a></h4><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/heroes/heroes.component.html" path="toh-pt5/src/app/heroes/heroes.component.html">&lt;h2&gt;My Heroes&lt;/h2&gt; &lt;ul class="heroes"&gt; &lt;li *<a href="api/common/NgForOf" class="code-anchor">ngFor</a>="let hero of heroes"&gt; &lt;a <a href="api/router/RouterLink" class="code-anchor">routerLink</a>="/detail/{{hero.id}}"&gt; &lt;span class="badge"&gt;{{hero.id}}&lt;/span&gt; {{hero.name}} &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;</code-pane><code-pane header="src/app/heroes/heroes.component.ts" path="toh-pt5/src/app/heroes/heroes.component.ts">import { <a href="api/core/Component" class="code-anchor">Component</a>, <a href="api/core/OnInit" class="code-anchor">OnInit</a> } from '@angular/core'; import { Hero } from '../hero'; import { HeroService } from '../hero.service'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-heroes', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './heroes.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: ['./heroes.component.css'] }) export class HeroesComponent implements <a href="api/core/OnInit" class="code-anchor">OnInit</a> { heroes: Hero[]; constructor(private heroService: HeroService) { } ngOnInit() { this.getHeroes(); } getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes =&gt; this.heroes = heroes); } }</code-pane><code-pane header="src/app/heroes/heroes.component.css" path="toh-pt5/src/app/heroes/heroes.component.css">/* HeroesComponent's private CSS styles */ .heroes { margin: 0 0 2em 0; list-style-type: none; padding: 0; width: 15em; } .heroes li { <a href="api/router/Scroll#position" class="code-anchor">position</a>: relative; cursor: pointer; background-color: #EEE; margin: .5em; padding: .3em 0; height: 1.6em; border-radius: 4px; } .heroes li:hover { color: #607D8B; background-color: #DDD; left: .1em; } .heroes a { color: #333; text-decoration: none; <a href="api/router/Scroll#position" class="code-anchor">position</a>: relative; display: block; width: 250px; } .heroes a:hover { color:#607D8B; } .heroes .badge { display: inline-block; font-size: small; color: white; padding: 0.8em 0.7em 0 0.7em; background-color:#405061; line-height: 1em; <a href="api/router/Scroll#position" class="code-anchor">position</a>: relative; left: -1px; top: -4px; height: 1.8em; min-width: 16px; text-align: right; margin-right: .8em; border-radius: 4px 0 0 4px; }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header mat-tab-header-pagination-controls-enabled"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-4-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-4-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/heroes/heroes.component.html</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-4-1" tabindex="-1" aria-posinset="2" aria-setsize="3" aria-controls="mat-tab-content-4-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/heroes/heroes.component.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-4-2" tabindex="-1" aria-posinset="3" aria-setsize="3" aria-controls="mat-tab-content-4-2" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/heroes/heroes.component.css</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:291px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-13 mat-tab-body-active ng-star-inserted" id="mat-tab-content-4-0" aria-labelledby="mat-tab-label-4-0"><div class="mat-tab-body-content ng-tns-c50-13 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/heroes/heroes.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;h2&gt;</span><span class="pln">My Heroes</span><span class="tag">&lt;/h2&gt;</span><span class="pln">
</span><span class="tag">&lt;ul</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"heroes"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;li</span><span class="pln"> *</span><a href="api/common/NgForOf" class="code-anchor"><span class="atn">ngFor</span></a><span class="pun">=</span><span class="atv">"let hero of heroes"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;a</span><span class="pln"> </span><a href="api/router/RouterLink" class="code-anchor"><span class="atn">routerLink</span></a><span class="pun">=</span><span class="atv">"/detail/{{hero.id}}"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"badge"</span><span class="tag">&gt;</span><span class="pln">{{hero.id}}</span><span class="tag">&lt;/span&gt;</span><span class="pln"> {{hero.name}}
    </span><span class="tag">&lt;/a&gt;</span><span class="pln">
  </span><span class="tag">&lt;/li&gt;</span><span class="pln">
</span><span class="tag">&lt;/ul&gt;</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-14 ng-star-inserted" id="mat-tab-content-4-1" aria-labelledby="mat-tab-label-4-1"><div class="mat-tab-body-content ng-tns-c50-14 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-15 ng-star-inserted" id="mat-tab-content-4-2" aria-labelledby="mat-tab-label-4-2"><div class="mat-tab-body-content ng-tns-c50-15 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><a id="herodetailcomponent"></a><h4 id="herodetailcomponent"><code>HeroDetailComponent</code><a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#herodetailcomponent"><i class="material-icons">link</i></a></h4><code-tabs ng-version="9.0.0-rc.11"><div style="display:none"><code-pane header="src/app/hero-detail/hero-detail.component.html" path="toh-pt5/src/app/hero-detail/hero-detail.component.html">&lt;div *<a href="api/common/NgIf" class="code-anchor">ngIf</a>="hero"&gt; &lt;h2&gt;{{hero.name | <a href="api/common/UpperCasePipe" class="code-anchor">uppercase</a>}} Details&lt;/h2&gt; &lt;div&gt;&lt;span&gt;id: &lt;/span&gt;{{hero.id}}&lt;/div&gt; &lt;div&gt; &lt;label&gt;name: &lt;input [(<a href="api/forms/NgModel" class="code-anchor">ngModel</a>)]="hero.name" placeholder="name"/&gt; &lt;/label&gt; &lt;/div&gt; &lt;button (click)="goBack()"&gt;go back&lt;/button&gt; &lt;/div&gt;</code-pane><code-pane header="src/app/hero-detail/hero-detail.component.ts" path="toh-pt5/src/app/hero-detail/hero-detail.component.ts">import { <a href="api/core/Component" class="code-anchor">Component</a>, <a href="api/core/OnInit" class="code-anchor">OnInit</a> } from '@angular/core'; import { <a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a> } from '@angular/router'; import { <a href="api/common/Location" class="code-anchor">Location</a> } from '@angular/common'; import { Hero } from '../hero'; import { HeroService } from '../hero.service'; @<a href="api/core/Component" class="code-anchor">Component</a>({ selector: 'app-hero-detail', <a href="api/core/Component#templateUrl" class="code-anchor">templateUrl</a>: './hero-detail.component.html', <a href="api/core/Component#styleUrls" class="code-anchor">styleUrls</a>: [ './hero-detail.component.css' ] }) export class HeroDetailComponent implements <a href="api/core/OnInit" class="code-anchor">OnInit</a> { hero: Hero; constructor( private route: <a href="api/router/ActivatedRoute" class="code-anchor">ActivatedRoute</a>, private heroService: HeroService, private location: <a href="api/common/Location" class="code-anchor">Location</a> ) {} ngOnInit(): void { this.getHero(); } getHero(): void { const id = +this.route.snapshot.paramMap.get('id'); this.heroService.getHero(id) .subscribe(hero =&gt; this.hero = hero); } goBack(): void { this.location.back(); } }</code-pane><code-pane header="src/app/hero-detail/hero-detail.component.css" path="toh-pt5/src/app/hero-detail/hero-detail.component.css">/* HeroDetailComponent's private CSS styles */ label { display: inline-block; width: 3em; margin: .5em 0; color: #607D8B; font-weight: bold; } input { height: 2em; font-size: 1em; padding-left: .4em; } button { margin-top: 20px; font-family: Arial; background-color: #eee; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; cursor: hand; } button:hover { background-color: #cfd8dc; } button:disabled { background-color: #eee; color: #ccc; cursor: auto; }</code-pane></div><mat-card class="mat-card"><mat-tab-group class="mat-tab-group code-tab-group mat-primary"><mat-tab-header class="mat-tab-header mat-tab-header-pagination-controls-enabled"><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4 mat-tab-header-pagination-disabled"><div class="mat-tab-header-pagination-chevron"></div></div><div class="mat-tab-label-container"><div role="tablist" class="mat-tab-list" style="transform:translateX(0)"><div class="mat-tab-labels"><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label mat-tab-label-active ng-star-inserted" id="mat-tab-label-5-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-5-0" aria-selected="true" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/hero-detail/hero-detail.component.html</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-5-1" tabindex="-1" aria-posinset="2" aria-setsize="3" aria-controls="mat-tab-content-5-1" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/hero-detail/hero-detail.component.ts</span></div></div><div role="tab" mattablabelwrapper="" mat-ripple="" cdkmonitorelementfocus="" class="mat-ripple mat-tab-label ng-star-inserted" id="mat-tab-label-5-2" tabindex="-1" aria-posinset="3" aria-setsize="3" aria-controls="mat-tab-content-5-2" aria-selected="false" aria-disabled="false"><div class="mat-tab-label-content"><span class="ng-star-inserted">src/app/hero-detail/hero-detail.component.css</span></div></div></div><mat-ink-bar class="mat-ink-bar" style="visibility:visible;left:0;width:338px"></mat-ink-bar></div></div><div aria-hidden="true" mat-ripple="" class="mat-ripple mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"><div class="mat-tab-header-pagination-chevron"></div></div></mat-tab-header><div class="mat-tab-body-wrapper"><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-16 mat-tab-body-active ng-star-inserted" id="mat-tab-content-5-0" aria-labelledby="mat-tab-label-5-0"><div class="mat-tab-body-content ng-tns-c50-16 ng-trigger ng-trigger-translateTab" style="transform:none"><aio-code class="ng-star-inserted" style=""><pre class="lang- prettyprint">      <button title="Copy code snippet" class="material-icons copy-button no-print ng-star-inserted" aria-label="Copy code snippet from src/app/hero-detail/hero-detail.component.html">
        <span aria-hidden="true">content_copy</span>
      </button>
      <code class="animated fadeIn"><span class="tag">&lt;div</span><span class="pln"> *</span><a href="api/common/NgIf" class="code-anchor"><span class="atn">ngIf</span></a><span class="pun">=</span><span class="atv">"hero"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;h2&gt;</span><span class="pln">{{hero.name | </span><a href="api/common/UpperCasePipe" class="code-anchor"><span class="pln">uppercase</span></a><span class="pln">}} Details</span><span class="tag">&lt;/h2&gt;</span><span class="pln">
  </span><span class="tag">&lt;div&gt;&lt;span&gt;</span><span class="pln">id: </span><span class="tag">&lt;/span&gt;</span><span class="pln">{{hero.id}}</span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div&gt;</span><span class="pln">
    </span><span class="tag">&lt;label&gt;</span><span class="pln">name:
      </span><span class="tag">&lt;input</span><span class="pln"> [(</span><a href="api/forms/NgModel" class="code-anchor"><span class="atn">ngModel</span></a><span class="pln">)]</span><span class="pun">=</span><span class="atv">"hero.name"</span><span class="pln"> </span><span class="atn">placeholder</span><span class="pun">=</span><span class="atv">"name"</span><span class="tag">/&gt;</span><span class="pln">
    </span><span class="tag">&lt;/label&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;button</span><span class="pln"> (</span><span class="atn">click</span><span class="pln">)</span><span class="pun">=</span><span class="atv">"goBack()"</span><span class="tag">&gt;</span><span class="pln">go back</span><span class="tag">&lt;/button&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code>
    </pre></aio-code></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-17 ng-star-inserted" id="mat-tab-content-5-1" aria-labelledby="mat-tab-label-5-1"><div class="mat-tab-body-content ng-tns-c50-17 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body><mat-tab-body role="tabpanel" class="mat-tab-body ng-tns-c50-18 ng-star-inserted" id="mat-tab-content-5-2" aria-labelledby="mat-tab-label-5-2"><div class="mat-tab-body-content ng-tns-c50-18 ng-trigger ng-trigger-translateTab" style="transform:translate3d(100%,0,0);min-height:1px"></div></mat-tab-body></div></mat-tab-group></mat-card></code-tabs><h2 id="summary" translation-result="on">小结<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#summary"><i class="material-icons">link</i></a></h2><h2 translation-origin="off" id="summary">Summary<a title="Link to this heading" class="header-link" aria-hidden="true" href="tutorial/toh-pt5#summary"><i class="material-icons">link</i></a></h2><ul><li><p translation-result="on">添加了 Angular <em>路由器</em>在各个不同组件之间导航。</p><p translation-origin="off">You added the Angular router to navigate among different components.</p></li><li><p translation-result="on">你使用一些 <code>&lt;a&gt;</code> 链接和一个 <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code> 把 <code>AppComponent</code> 转换成了一个导航用的壳组件。</p><p translation-origin="off">You turned the <code>AppComponent</code> into a navigation shell with <code>&lt;a&gt;</code> links and a <code>&lt;<a href="api/router/RouterOutlet" class="code-anchor">router-outlet</a>&gt;</code>.</p></li><li><p translation-result="on">你在 <code>AppRoutingModule</code> 中配置了路由器。</p><p translation-origin="off">You configured the router in an <code>AppRoutingModule</code> </p></li><li><p translation-result="on">你定义了一些简单路由、一个重定向路由和一个参数化路由。</p><p translation-origin="off">You defined simple routes, a redirect route, and a parameterized route.</p></li><li><p translation-result="on">你在 <code>&lt;a&gt;</code> 元素中使用了 <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> 指令。</p><p translation-origin="off">You used the <code><a href="api/router/RouterLink" class="code-anchor">routerLink</a></code> directive in anchor elements.</p></li><li><p translation-result="on">你把一个紧耦合的主从视图重构成了带路由的详情视图。</p><p translation-origin="off">You refactored a tightly-coupled master/detail view into a routed detail view.</p></li><li><p translation-result="on">你使用路由链接参数来导航到所选英雄的详情视图。</p><p translation-origin="off">You used router link parameters to navigate to the detail view of a user-selected hero.</p></li><li><p translation-result="on">在多个组件之间共享了 <code>HeroService</code> 服务。</p><p translation-origin="off">You shared the <code>HeroService</code> among multiple components.</p></li></ul></div></div></aio-doc-viewer></main></mat-sidenav-content></mat-sidenav-container><div class="toc-container no-print ng-star-inserted"><aio-lazy-ce selector="aio-toc"><aio-toc ng-version="9.0.0-rc.11"><div class="toc-inner no-print collapsed ng-star-inserted"><ul class="toc-list"><li class="h1 ng-star-inserted active" title="路由"><a href="tutorial/toh-pt5#add-in-app-navigation-routing">路由</a></li><li class="h2 ng-star-inserted" title="添加 AppRoutingModule"><a href="tutorial/toh-pt5#add-the-approutingmodule">添加 <code>AppRoutingModule</code></a></li><li class="h3 ng-star-inserted" title="路由"><a href="tutorial/toh-pt5#routes">路由</a></li><li class="h3 ng-star-inserted" title="RouterModule.forRoot()"><a href="tutorial/toh-pt5#routermoduleforroot"><code>RouterModule.forRoot()</code></a></li><li class="h2 ng-star-inserted" title="添加路由出口 RouterOutlet"><a href="tutorial/toh-pt5#add-routeroutlet">添加路由出口 <code>RouterOutlet</code></a></li><li class="h2 ng-star-inserted" title="添加路由链接 (routerLink)"><a href="tutorial/toh-pt5#add-a-navigation-link-routerlink">添加路由链接 (<code>routerLink</code>)</a></li><li class="h2 ng-star-inserted" title="添加仪表盘视图"><a href="tutorial/toh-pt5#add-a-dashboard-view">添加仪表盘视图</a></li><li class="h3 ng-star-inserted" title="添加仪表盘路由"><a href="tutorial/toh-pt5#add-the-dashboard-route">添加仪表盘路由</a></li><li class="h3 ng-star-inserted" title="添加默认路由"><a href="tutorial/toh-pt5#add-a-default-route">添加默认路由</a></li><li class="h3 ng-star-inserted" title="把仪表盘链接添加到壳组件中"><a href="tutorial/toh-pt5#add-dashboard-link-to-the-shell">把仪表盘链接添加到壳组件中</a></li><li class="h2 ng-star-inserted" title="导航到英雄详情"><a href="tutorial/toh-pt5#navigating-to-hero-details">导航到英雄详情</a></li><li class="h3 ng-star-inserted" title="从 HeroesComponent 中删除英雄详情"><a href="tutorial/toh-pt5#delete-hero-details-from-heroescomponent">从 <code>HeroesComponent</code> 中删除<em>英雄详情</em></a></li><li class="h3 ng-star-inserted" title="添加英雄详情视图"><a href="tutorial/toh-pt5#add-a-hero-detail-route">添加<em>英雄详情</em>视图</a></li><li class="h3 ng-star-inserted" title="DashboardComponent 中的英雄链接"><a href="tutorial/toh-pt5#dashboardcomponent-hero-links"><code>DashboardComponent</code> 中的英雄链接</a></li><li class="h3 ng-star-inserted" title="HeroesComponent 中的英雄链接"><a href="tutorial/toh-pt5#heroescomponent-hero-links"><code>HeroesComponent</code> 中的英雄链接</a></li><li class="h2 ng-star-inserted" title="支持路由的 HeroDetailComponent"><a href="tutorial/toh-pt5#routable-herodetailcomponent">支持路由的 <code>HeroDetailComponent</code></a></li><li class="h3 ng-star-inserted" title="从路由参数中提取 id"><a href="tutorial/toh-pt5#extract-the-id-route-parameter">从路由参数中提取 <code>id</code></a></li><li class="h3 ng-star-inserted" title="添加 HeroService.getHero()"><a href="tutorial/toh-pt5#add-heroservicegethero">添加 <code>HeroService.getHero()</code></a></li><li class="h3 ng-star-inserted" title="回到原路"><a href="tutorial/toh-pt5#find-the-way-back">回到原路</a></li><li class="h2 ng-star-inserted" title="查看最终代码"><a href="tutorial/toh-pt5#final-code-review">查看最终代码</a></li><li class="h2 ng-star-inserted" title="小结"><a href="tutorial/toh-pt5#summary">小结</a></li></ul></div></aio-toc></aio-lazy-ce></div><footer class="no-print"><aio-footer><div class="grid-fluid"><div class="footer-block ng-star-inserted"><h3>资源</h3><ul><li class="ng-star-inserted"><a class="link" href="about" title="Angular 贡献者。">关于</a></li><li class="ng-star-inserted"><a class="link" href="resources" title="网络上的 Angular 工具、培训、博客等">资源列表</a></li><li class="ng-star-inserted"><a class="link" href="presskit" title="我们的联系方式、LOGO 和品牌">宣传资料</a></li><li class="ng-star-inserted"><a class="link" href="https://blog.angular.io/" title="Angular 官方博客">博客</a></li><li class="ng-star-inserted"><a class="link" href="analytics" title="Angular 使用情况分析">使用情况分析</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>帮助</h3><ul><li class="ng-star-inserted"><a class="link" href="https://stackoverflow.com/questions/tagged/angular" title="Stack Overflow: 这里的社区会回答你关于 Angular 的技术问题">Stack Overflow</a></li><li class="ng-star-inserted"><a class="link" href="https://gitter.im/angular/angular" title="和老鸟聊 Angular">Gitter</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/angular/issues" title="在 github 上报告问题和建议。">报告问题</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md" title="让我们彼此尊重">行为规范</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>社区</h3><ul><li class="ng-star-inserted"><a class="link" href="events" title="Angular events around the world.">活动</a></li><li class="ng-star-inserted"><a class="link" href="http://www.meetup.com/topics/angularjs/" title="参加聚会，向别的开发人员学习">聚会</a></li><li class="ng-star-inserted"><a class="link" href="https://twitter.com/angular" title="Twitter">Twitter</a></li><li class="ng-star-inserted"><a class="link" href="https://github.com/angular/angular" title="GitHub">GitHub</a></li><li class="ng-star-inserted"><a class="link" href="contribute" title="向 Angular 做贡献">做贡献</a></li></ul></div><div class="footer-block ng-star-inserted"><h3>多语言</h3><ul><li class="ng-star-inserted"><a class="link" href="https://angular.io/" title="English Version.">English Version</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.tw/" title="正體中文版">正體中文版</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.jp/" title="日本語版">日本語版</a></li><li class="ng-star-inserted"><a class="link" href="https://angular.kr/" title="한국어">한국어</a></li></ul></div></div><p>Super-powered by Google ©2010-2020. 代码授权方式：<a href="license" title="License text">MIT-style License</a>. 文档授权方式：<a href="http://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.</p><p>当前版本：9.0.1-build.109+sha.7a49faba.</p></aio-footer></footer><div class="cdk-visually-hidden ng-star-inserted"><mat-icon role="img" class="mat-icon notranslate material-icons mat-icon-no-color" aria-hidden="true">&nbsp;</mat-icon></div></aio-shell><noscript><div class="background-sky hero"></div><section id="intro" style="text-shadow:1px 1px #1976d2"><div class="hero-logo"><img src="assets/images/logos/angular/angular.svg" width="250" height="250" alt="Angular"></div><div class="homepage-container"><div class="hero-headline">一套框架，多种平台<br>移动 &amp; 桌面</div></div></section><h2 style="color:red;margin-top:40px;position:relative;text-align:center;text-shadow:1px 1px #fafafa"><b><i>该网站需要浏览器支持 JavaScript</i></b></h2></noscript><script src="runtime-es2015.811b066977719df5af39.js" type="module"></script><script src="runtime-es5.811b066977719df5af39.js" nomodule="" defer=""></script><script src="polyfills-es5.1494ca908613f3429457.js" nomodule="" defer=""></script><script src="polyfills-es2015.9057a05c650bf60ecbf4.js" type="module"></script><script src="main-es2015.4e9aa34b562bab1382ab.js" type="module"></script><script src="main-es5.4e9aa34b562bab1382ab.js" nomodule="" defer=""></script><div class="cdk-live-announcer-element cdk-visually-hidden" aria-atomic="true" aria-live="polite"></div></body></html>